LinearRegression

predict and evaluate multivariate linear regression model

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 15 11:37:53 2019
https://www.ritchieng.com/machine-learning-evaluate-linear-regression-mo...
@author: K
"""

# imports
import pandas as pd
import seaborn as sns
import statsmodels.formula.api as smf
from sklearn.linear_model import LinearRegression
from sklearn import metrics
from sklearn.cross_validation import train_test_split
import numpy as np

# allow plots to appear directly in the notebook
#%matplotlib inline

sklearn linear_model LinearRegression on Salaries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import warnings
#from IPython import get_ipython
#ipy = get_ipython()
#if ipy is not None:
#    ipy.run_line_magic('matplotlib', 'inline')
sns.set()
#%matplotlib inline

df = pd.read_csv("./SalaryData1.csv")
print(df.shape)
print(df.isnull().values.any())

Regression lineaire avec des listes en entrées

# -*- coding: utf-8 -*-
"""
Regression lineaire avec des listes en entrées
"""

import matplotlib.pyplot as plt
import numpy as np
import statsmodels.api as sm


#Farm size in hectares
X=[1,1,2,2,2.3,3,3,3.5,4,4.3]
#Crop yield in tons
Y=[6.9,6.7,13.8,14.7,16.5,18.7,17.4,22,29.4,34.5]
"""
#    By default, OLS implementation of statsmodels does not include an intercept 
#     in the model unless we are using formulas.
#    We need to explicitly specify the use of intercept in OLS method by 
#     adding a constant term.
X_1 = sm.add_constant(X)
#print(X_1)
Subscribe to LinearRegression