Skip to content

Instantly share code, notes, and snippets.

@MCMXCIII
Last active October 19, 2019 17:10
Show Gist options
  • Save MCMXCIII/2a7f83670e3f3d35c745d8d8ef53bdd0 to your computer and use it in GitHub Desktop.
Save MCMXCIII/2a7f83670e3f3d35c745d8d8ef53bdd0 to your computer and use it in GitHub Desktop.
Finished Single line?
import pandas as pd
import numpy as np
import mathplotlib.pyploy as plt
immport seaborn as seabornInstance.model_selection
from sklearn import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn iport metrics
%mathplotlib inline
dataset= pd.read_csv("path to csv dataset CLEAN PLEASE-DEFINE VARS")
dataset.shape
#incoming set to start model
'''
dataset.plot(x='MinTemp',y='MaxTemp', style='o')
plt.title()
plt.xlabel()
plt.ylabel()
plt.show()
'''
#Showing figures
'''
plt.figure(figsize=(15,10))
plt.tight_layout()
seabornInstance.distplot(dataset['Maxtemp'])
'''
#dividing the data simple figure
X= dataset['MinTemp'].values.reshape(-1,1)
y= dataset['MinTemp'].values.reshape(-1,1)
#TRAINING!
X_train, X_testx y_train, y_test = train_test_split(X,y,test_size-0.2, random_state=0)
#Training this algo
regressor = LinearRegression()
regressor.fir(X_train, y_train)
#retrieve intercept
print(regressor.intercept)
#For retrieving the slope
print(regressor.coef_)
#Make some predictions
y_pred = regressor.preddict(X_test)
#compare output for X_test
#This is a Dataframe now
df = pd..DataFrame({'Actual': y_test.flaten(), 'Predictied':y_pred.flatten()})
# now visualize everything
df1 = df.head(25)
df1.plot(kind='bar ', figsize=(16,10))
plt.grid(which='major',linestyle='-', linewidth='0.5', color='blue')
plt.grid(which='minor',linestyle=':', linewidth='0.5', color='black')
plt.show
#plot dem lines brah
plt.scatter(X_test, y_test, color='grey')
plt.plot(X_test,y_test,color='red',linewidth=2)
plt.show
#Multiline Regression
#check the next file
from sklearn import lineadr_model
#reg = linear_model.LinearRegression()
#reg.fit([])
#LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,
# normalize=False)
#reg.coef_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment