Untitled
unknown
python
3 years ago
1.4 kB
7
Indexable
import pandas as pd
def download_data():
import os
import urllib
if os.path.exists('cars.csv'):
print('Data already downloaded')
return
urllib.request.urlretrieve('https://think.cs.vt.edu/corgis/datasets/csv/cars/cars.csv','cars.csv')
print('Download Complete')
download_data()
df = pd.read_csv('cars.csv')
df.head()
df = df[df['Make'] == 'Honda']
df = df[df['Fuel Information.Fuel Types'] == 'Gasoline']
df = df[df['Fuel Information.Combined MPG'] < df['Fuel Information.Combined MPG'].quantile(0.9)]
features = ['Fuel Information.Highway MPG', 'Engine Information.Engine Statistics.Horsepower']
x = df[features]
x = x.values
x = x.astype('float32')
x = (x-x.min())/(x.max()-x.min())
y = df['Fuel Information.Combined MPG']
y = y.astype('float32')
y = (y-y.min())/(y.max()-y.min())
y = y.values
import matplotlib.pyplot as plt
plt.scatter(x[:,0], y, c='r',label='data')
plt.show()
plt.scatter(x[:,1], y, c='r',label='data')
plt.show()
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(1, input_dim=2, kernel_initializer='normal', activation='linear'))
model.compile(loss='mse', optimizer='adam', metrics=['mse'])
model.fit(x, y, epochs=100, batch_size=1, verbose=1)
scores = model.evaluate(x, y, verbose=0)
print(model.get_weights())
Editor is loading...