Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

keras linear regression

from pylab import *
from keras.models import Sequential
from keras.layers import Dense

#Generate dummy data
data = data = linspace(1,2,100).reshape(-1,1)
y = data*5

#Define the model
def baseline_model():
   model = Sequential()
   model.add(Dense(1, activation = 'linear', input_dim = 1))
   model.compile(optimizer = 'rmsprop', loss = 'mean_squared_error', metrics = ['accuracy'])
   return model


#Use the model
regr = baseline_model()
regr.fit(data,y,epochs =200,batch_size = 32)
plot(data, regr.predict(data), 'b', data,y, 'k.')
Comment

PREVIOUS NEXT
Code Example
Python :: import local module python 
Python :: get mac address python 
Python :: python tkinter scrollbar widget 
Python :: python wait for x seconds 
Python :: qlistwidget item clicked event pyqt 
Python :: randomforestregressor in sklearn 
Python :: Plot regression line from sklearn 
Python :: distplot with plotly 
Python :: Read all the lines as a list in a file using the readlines() function 
Python :: how to get a number from a string in python 
Python :: in pandas how to start an index from a specific number 
Python :: pandas replace row values based on condition 
Python :: endswith python 
Python :: python console width 
Python :: keras example 
Python :: sqlite query in python 
Python :: assign multiple variables in python 
Python :: multiple variables in for loop python 
Python :: list of numbers 
Python :: transpose matrix numpy 
Python :: select non nan values python 
Python :: python recurrent timer 
Python :: hardest python questions 
Python :: python replace string 
Python :: dataframe add row 
Python :: 13 pseudo random numbers between 0 to 3 python 
Python :: python nested list comprehension 
Python :: python package version 
Python :: imread real color cv2 
Python :: python ftplib get list of directories 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =