Logo elodees  elodees

Une IA bien-veillante pour un monde meilleur













Seuls les caractères alphabétiques accentués ou non ainsi que l'espace sont acceptés

Logo IA




Régression évoluée





Pas encore de compte ?

Inscrivez-vous pour accéder à tous les contenus




Prévision du prix des voitures
Régression avancée utilisant Lasso et Ridge



Testé sous Anaconda et Python 3.7

# Advanced Regression
 
#Importing the required libraries
 
import warnings
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split, GridSearchCV, KFold
from sklearn.linear_model import LinearRegression, Ridge, Lasso
from sklearn.feature_selection import RFE
from sklearn.metrics import r2_score
 
warnings.filterwarnings('ignore')
 
# Performing baisc checks in the dataset
 
house_price = pd.read_csv('train.csv')
 
print(house_price.shape)
 
print(house_price.info())
 
print(house_price.head())
 
print(house_price.describe([0.25,0.50,0.75,0.99]))
 
# Checking the dataset for the amount of nulls present
 
print(round(house_price.isnull().sum()/len(house_price.index),2).sort_values(ascending=False).head(18))
 
# Considering 10% as my threshold and dropping the column having more then the threshold
 
print(round(house_price.isnull().sum()/len(house_price.index),2)[round(house_price.isnull().sum()/
                                                                 len(house_price.index),2).values>0.10])
house_price = house_price.drop(['LotFrontage','Alley','FireplaceQu','PoolQC','Fence','MiscFeature','MoSold'],axis='columns')
 
# Checking the columns where the missing values between 0-10%
 
print(round(house_price.isnull().sum()/len(house_price.index),2)[round(house_price.isnull().sum()/
                                                                 len(house_price.index),2).values>0.00])
# Before going further we will try to convert the Year columns with the age where we are going to fill these columns with number , And if we query the max year for all these columns these will come out to be 2010 ,EX suppose the YearBuilt=2000 , Then YearBuiltOld = 2010-2000 =10
 
house_price['YearBuilt_Old'] = house_price.YearBuilt.max()-house_price.YearBuilt
house_price['YearRemodAdd_Old'] = house_price.YearRemodAdd.max()-house_price.YearRemodAdd
house_price['GarageYrBlt_Old'] = house_price.GarageYrBlt.max()-house_price.GarageYrBlt
house_price['YrSold_Old'] = house_price.YrSold.max()-house_price.YrSold
print(house_price[['YearBuilt','YearRemodAdd','GarageYrBlt','YrSold','YearBuilt_Old','YearRemodAdd_Old',
             'GarageYrBlt_Old','YrSold_Old']].sample(10))
 
# Lets drop the actual Year columns
 
house_price = house_price.drop(['YearBuilt','YearRemodAdd','GarageYrBlt','YrSold'],axis='columns')
 
# Imputing missing value
 
# Notice imputing GarageYrBlt_Old with -1 as these house donot have garage
 
house_price.MasVnrType.fillna('None',inplace=True)
house_price.MasVnrArea.fillna(house_price.MasVnrArea.mean(),inplace=True)
house_price.BsmtQual.fillna('TA',inplace=True)
house_price.BsmtCond.fillna('TA',inplace=True)
house_price.BsmtExposure.fillna('No',inplace=True)
house_price.BsmtFinType1.fillna('Unf',inplace=True)
house_price.BsmtFinType2.fillna('Unf',inplace=True)
house_price.GarageType.fillna('Attchd',inplace=True)
house_price.GarageYrBlt_Old.fillna(-1,inplace=True)
house_price.GarageFinish.fillna('Unf',inplace=True)
house_price.GarageQual.fillna('TA',inplace=True)
house_price.GarageCond.fillna('TA',inplace=True)
 
# As per the analysis 'Street' & 'Utilities' is explaining the lowest valrience hence dropping these columns
 
house_price.Street.value_counts()
house_price.Utilities.value_counts()
house_price = house_price.drop(['Street','Utilities'],axis='columns')
 
# 'Id' column is also of no use for our analysis hence dropping the column
 
house_price = house_price.drop('Id',axis='columns')
 
print(house_price[list(house_price.dtypes[house_price.dtypes!='object'].index)].describe())
 
# sns.boxplot(y = house_price['PoolArea'])
# house_price['WoodDeckSF'].value_counts()
 
# Lets plot some graph for the EDA purpose
 
plt.figure(figsize=(16,8))
plt.subplot(2,3,1)
plt.scatter(house_price.MasVnrArea,house_price.SalePrice)
plt.subplot(2,3,2)
plt.scatter(house_price.TotalBsmtSF,house_price.SalePrice)
plt.subplot(2,3,3)
plt.scatter(house_price['1stFlrSF'],house_price.SalePrice)
plt.subplot(2,3,4)
plt.scatter(house_price['GarageArea'],house_price.SalePrice)
plt.subplot(2,3,5)
plt.scatter(house_price['GrLivArea'],house_price.SalePrice)
plt.subplot(2,3,6)
plt.scatter(house_price['WoodDeckSF'],house_price.SalePrice)
 
# Plotting heatmap to check the corellation between varables
 
plt.figure(figsize=(16,16))
sns.heatmap(house_price[list(house_price.dtypes[house_price.dtypes!='object'].index)].corr(),annot=True)
plt.show()
 
# Below function is used for hadling the outliers where i am taking the lower and upper quantile as 0.25 & 0.99 respectively
 
print(house_price.shape)
 
num_col = list(house_price.dtypes[house_price.dtypes !='object'].index)
num_col = ['LotArea','MasVnrArea','BsmtFinSF1','BsmtFinSF2','TotalBsmtSF','1stFlrSF','GrLivArea','OpenPorchSF',
           'EnclosedPorch','3SsnPorch',
           'ScreenPorch' ,'PoolArea','MiscVal','SalePrice']
def drop_outliers(x):
    for col in num_col:
        Q1 = x[col].quantile(.25)
        Q3 = x[col].quantile(.99)
        IQR = Q3-Q1
        x =  x[(x[col] >= (Q1-(1.5*IQR))) & (x[col] <= (Q3+(1.5*IQR)))] 
    return x   
 
house_price = drop_outliers(house_price)
 
print(house_price.shape)
 
print(house_price[list(house_price.dtypes[house_price.dtypes=='object'].index)].head())
 
# Lets check for the below columns here we can clearly see that these are having some kind of order and hence we can say these are ordinal in nature
 
print(house_price[['LandSlope','ExterQual','BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2',
            'HeatingQC','CentralAir',  'KitchenQual','GarageFinish','GarageQual','GarageCond',
             'ExterCond','LotShape']].head())
 
house_price['LandSlope'] = house_price.LandSlope.map({'Gtl':0,'Mod':1,'Sev':2})
house_price['ExterQual'] = house_price.ExterQual.map({'Po':0,'Fa':1,'TA':2,'Gd':3,'Ex':4})
house_price['BsmtQual'] = house_price.BsmtQual.map({'NA':0,'Po':1,'Fa':2,'TA':3,'Gd':4,'Ex':5})
house_price['BsmtCond'] = house_price.BsmtCond.map({'NA':0,'Po':1,'Fa':2,'TA':3,'Gd':4,'Ex':5})
house_price['BsmtExposure'] = house_price.BsmtExposure.map({'NA':0,'No':1,'Mn':2,'Av':3,'Gd':4})
house_price['BsmtFinType1'] = house_price.BsmtFinType1.map({'NA':0,'Unf':1,'LwQ':2,'Rec':3,'BLQ':4,'ALQ':5,'GLQ':6})
house_price['BsmtFinType2'] = house_price.BsmtFinType2.map({'NA':0,'Unf':1,'LwQ':2,'Rec':3,'BLQ':4,'ALQ':5,'GLQ':6})
house_price['HeatingQC'] = house_price.HeatingQC.map({'Po':0,'Fa':1,'TA':2,'Gd':3,'Ex':4})
house_price['CentralAir'] = house_price.CentralAir.map({'N':0,'Y':1})
house_price['KitchenQual'] = house_price.KitchenQual.map({'Po':0,'Fa':1,'TA':2,'Gd':3,'Ex':4})
house_price['GarageFinish'] = house_price.GarageFinish.map({'NA':0,'Unf':1,'RFn':2,'Fin':3})
house_price['GarageQual'] = house_price.GarageQual.map({'NA':0,'Po':1,'Fa':2,'TA':3,'Gd':4,'Ex':5})
house_price['GarageCond'] = house_price.GarageCond.map({'NA':0,'Po':1,'Fa':2,'TA':3,'Gd':4,'Ex':5})
house_price['ExterCond'] = house_price.ExterCond.map({'Po':0,'Fa':1,'TA':2,'Gd':3,'Ex':4})
house_price['LotShape'] = house_price.LotShape.map({'IR1':0,'IR2':1,'IR3':2,'Reg':3})
 
# Lets take a look into the converted columns
 
print(house_price[['LandSlope','ExterQual','BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2',
            'HeatingQC','CentralAir',  'KitchenQual','GarageFinish','GarageQual','GarageCond',
             'ExterCond','LotShape']].head())
 
# Creating and joining dummy column with the actual dataset
 
dummy_col = pd.get_dummies(house_price[['MSZoning','LandContour','LotConfig','Neighborhood','Condition1','Condition2','BldgType',
             'HouseStyle','RoofStyle','RoofMatl','Exterior1st',  'Exterior2nd','MasVnrType','Foundation',
             'Heating','Electrical','Functional','GarageType','PavedDrive','SaleType','SaleCondition']],
                           drop_first=True)
 
house_price = pd.concat([house_price,dummy_col],axis='columns')
 
house_price = house_price.drop(['MSZoning','LandContour','LotConfig','Neighborhood','Condition1','Condition2','BldgType',
             'HouseStyle','RoofStyle','RoofMatl','Exterior1st',  'Exterior2nd','MasVnrType','Foundation',
             'Heating','Electrical','Functional','GarageType','PavedDrive','SaleType','SaleCondition'],axis='columns')
 
# Let us check the distribution of our target variable before scaling and Splitting
 
plt.figure(figsize=(16,6))
sns.distplot(house_price.SalePrice)
plt.show()
 
# Creating train and test dataset for validation purpose
 
df_train,df_test = train_test_split(house_price,train_size=0.7,test_size=0.3,random_state=42)
 
print(house_price[['LandSlope','ExterQual','BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinType2',
            'HeatingQC','CentralAir',  'KitchenQual','GarageFinish','GarageQual','GarageCond',
             'ExterCond','LotShape']].head())
 
# Scaling the train dataset
 
# Note as scale of our dependent valriable SalePrice is very different with the independent variable i am scaling the dependent variable
 
num_col = ['MSSubClass','LotArea','OverallQual','OverallCond',
           'MasVnrArea','BsmtFinSF1',
           'BsmtFinSF2','BsmtUnfSF','TotalBsmtSF','1stFlrSF','2ndFlrSF',
           'LowQualFinSF','GrLivArea','BsmtFullBath','BsmtHalfBath','FullBath','HalfBath','BedroomAbvGr',
           'KitchenAbvGr','TotRmsAbvGrd','Fireplaces','GarageCars',
           'GarageArea','WoodDeckSF','OpenPorchSF','EnclosedPorch','3SsnPorch',
           'ScreenPorch','PoolArea','MiscVal','SalePrice']
 
# Lets check the distribution again after scaling
 
scaler = StandardScaler()
df_train[num_col] = scaler.fit_transform(df_train[num_col])
df_test[num_col] = scaler.transform(df_test[num_col])
 
plt.figure(figsize=(16,6))
plt.subplot(121)
sns.distplot(df_train.SalePrice)
plt.subplot(122)
sns.distplot(df_test.SalePrice)
 
# Spliting the dependent and independent variable
 
y_train = df_train.pop('SalePrice')
X_train = df_train
 
y_test = df_test.pop('SalePrice')
X_test = df_test
 
# Now using RFE lets try to to find the optimal number of feature
 
# Note : I cannot use RFE with GridSearchCV as 192 variable with 5 folds will create 960 fit and it will take more then 1 Hour to get the result so i am using RFE directly
 
print(len(X_train.columns))
 
lm  = LinearRegression()
lm.fit(X_train,y_train)
rfe = RFE(lm)
rfe.fit(X_train,y_train)
 
rfe_scores = pd.DataFrame(list(zip(X_train.columns,rfe.support_,rfe.ranking_)))
rfe_scores.columns = ['Column_Names','Status','Rank']
 
rfe_sel_columns = list(rfe_scores[rfe_scores.Status==True].Column_Names)
 
# Lets filter the train and test set for the RFE selected columns
 
X_train = X_train[rfe_sel_columns]
X_test = X_test[rfe_sel_columns]
 
# Lets try first with the Lasso regression model
 
lm = Lasso(alpha=0.001)
lm.fit(X_train,y_train)
 
y_train_pred = lm.predict(X_train)
print(r2_score(y_true=y_train,y_pred=y_train_pred))
 
y_test_pred  = lm.predict(X_test)
print(r2_score(y_true=y_test,y_pred=y_test_pred))
 
model_parameter = list(lm.coef_)
model_parameter.insert(0,lm.intercept_)
model_parameter = [round(x,3) for x in model_parameter]
col = df_train.columns
col.insert(0,'Constant')
print(list(zip(col,model_parameter)))
 
model_parameter = list(lm.coef_)
model_parameter.insert(0,lm.intercept_)
model_parameter = [round(x,3) for x in model_parameter]
col = df_train.columns
col.insert(0,'Constant')
list(zip(col,model_parameter))
 
# Now lets try to improve our model with the optimal value of alpha using GridSearchCV
 
folds = KFold(n_splits=10,shuffle=True,random_state=42)
 
hyper_param = {'alpha':[0.001, 0.01, 0.1,1.0, 5.0, 10.0,20.0]}
 
model = Lasso()
 
model_cv = GridSearchCV(estimator = model,
                        param_grid=hyper_param,
                        scoring='r2',
                        cv=folds,
                        verbose=1,
                        return_train_score=True
                       )
 
model_cv.fit(X_train,y_train)
 
cv_result_l = pd.DataFrame(model_cv.cv_results_)
cv_result_l['param_alpha'] = cv_result_l['param_alpha'].astype('float32')
print(cv_result_l.head())
 
plt.figure(figsize=(16,8))
plt.plot(cv_result_l['param_alpha'],cv_result_l['mean_train_score'])
plt.plot(cv_result_l['param_alpha'],cv_result_l['mean_test_score'])
plt.xscale('log')
plt.ylabel('R2 Score')
plt.xlabel('Alpha')
plt.show()
 
# Checking the best parameter(Alpha value)
print(model_cv.best_params_)
 
lasso = Lasso(alpha=0.001)
lasso.fit(X_train,y_train)
 
y_train_pred = lasso.predict(X_train)
y_test_pred = lasso.predict(X_test)
 
print(r2_score(y_true=y_train,y_pred=y_train_pred))
print(r2_score(y_true=y_test,y_pred=y_test_pred))
 
model_param = list(lasso.coef_)
model_param.insert(0,lasso.intercept_)
cols = df_train.columns
cols.insert(0,'const')
lasso_coef = pd.DataFrame(list(zip(cols,model_param)))
lasso_coef.columns = ['Featuere','Coef']
 
print(lasso_coef.sort_values(by='Coef',ascending=False).head(10))
 
# Now lets use the ridge regression
 
ridge = Ridge(alpha=0.001)
ridge.fit(X_train,y_train)
 
y_train_pred = ridge.predict(X_train)
print(r2_score(y_train,y_train_pred))
y_test_pred = ridge.predict(X_test)
print(r2_score(y_test,y_test_pred))
 
# As we can see the above alpha value is not optimal for ridge there are sign of overfitting the clear difference we can see in the train and test score
 
# Now lets try to improve our model with the optimal value of alpha using GridSearchCV
 
folds  = KFold(n_splits=10,shuffle=True,random_state=42)
 
hyper_param = {'alpha':[0.001,0.01,0.1,0.2,0.5,0.9,1.0, 5.0, 10.0,20.0]}
 
model = Ridge()
 
model_cv = GridSearchCV(estimator=model,
                        param_grid=hyper_param,
                        scoring='r2',
                        cv=folds,
                        verbose=1,
                        return_train_score=True)
 
model_cv.fit(X_train,y_train)
 
cv_result_r = pd.DataFrame(model_cv.cv_results_)
cv_result_r['param_alpha'] = cv_result_r['param_alpha'].astype('float32')
print(cv_result_r.head())
 
plt.figure(figsize=(16,8))
plt.plot(cv_result_r['param_alpha'],cv_result_r['mean_train_score'])
plt.plot(cv_result_r['param_alpha'],cv_result_r['mean_test_score'])
plt.xlabel('Alpha')
# plt.xscale('log')
plt.ylabel('R2 Score')
plt.show()
 
# On the basis of above graph lets create the model
 
# Checking the best parameter(Alpha value)
print(model_cv.best_params_)
 
ridge = Ridge(alpha = 0.9)
ridge.fit(X_train,y_train)
 
y_pred_train = ridge.predict(X_train)
print(r2_score(y_train,y_pred_train))
 
y_pred_test = ridge.predict(X_test)
print(r2_score(y_test,y_pred_test))
 
model_parameter = list(ridge.coef_)
model_parameter.insert(0,ridge.intercept_)
cols = df_train.columns
cols.insert(0,'constant')
ridge_coef = pd.DataFrame(list(zip(cols,model_parameter)))
ridge_coef.columns = ['Feaure','Coef']
 
print(ridge_coef.sort_values(by='Coef',ascending=False).head(10))
 
# After creating model in both Ridge and Lasso we can see that the r2_scores are almost same for both of them but as lasso will penalize more on the dataset and can also help in feature elemination i am goint to consider that as my final model.
 
# Final Model
 
lasso = Lasso(alpha=0.001)
lasso.fit(X_train,y_train)
 
y_train_pred = lasso.predict(X_train)
y_test_pred = lasso.predict(X_test)
 
print(r2_score(y_true=y_train,y_pred=y_train_pred))
print(r2_score(y_true=y_test,y_pred=y_test_pred))
 
# After compairing both the model we can see that the below Features are best explaining the DataSet
 
#MiscVal      : $Value of miscellaneous feature 
#BsmtHalfBath : Basement half bathrooms
#LowQualFinSF : Low quality finished square feet (all floors)
#BsmtFullBath : Basement full bathrooms
#HalfBath     : Half baths above grade
 
# Best alpha value for Lasso : {'alpha': 0.001}
# Best alpha value for Ridge : {'alpha': 0.9}
 


Advanced-Regression-using-Lasso-and-Ridge - GitHub



(1460, 81)



RangeIndex: 1460 entries, 0 to 1459

Data columns (total 81 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Id 1460 non-null int64
1 MSSubClass 1460 non-null int64
2 MSZoning 1460 non-null object
3 LotFrontage 1201 non-null float64
4 LotArea 1460 non-null int64
5 Street 1460 non-null object
6 Alley 91 non-null object
7 LotShape 1460 non-null object
8 LandContour 1460 non-null object
9 Utilities 1460 non-null object
10 LotConfig 1460 non-null object
11 LandSlope 1460 non-null object
12 Neighborhood 1460 non-null object
13 Condition1 1460 non-null object
14 Condition2 1460 non-null object
15 BldgType 1460 non-null object
16 HouseStyle 1460 non-null object
17 OverallQual 1460 non-null int64
18 OverallCond 1460 non-null int64
19 YearBuilt 1460 non-null int64
20 YearRemodAdd 1460 non-null int64
21 RoofStyle 1460 non-null object
22 RoofMatl 1460 non-null object
23 Exterior1st 1460 non-null object
24 Exterior2nd 1460 non-null object
25 MasVnrType 1452 non-null object
26 MasVnrArea 1452 non-null float64
27 ExterQual 1460 non-null object
28 ExterCond 1460 non-null object
29 Foundation 1460 non-null object
30 BsmtQual 1423 non-null object
31 BsmtCond 1423 non-null object
32 BsmtExposure 1422 non-null object
33 BsmtFinType1 1423 non-null object
34 BsmtFinSF1 1460 non-null int64
35 BsmtFinType2 1422 non-null object
36 BsmtFinSF2 1460 non-null int64
37 BsmtUnfSF 1460 non-null int64
38 TotalBsmtSF 1460 non-null int64
39 Heating 1460 non-null object
40 HeatingQC 1460 non-null object
41 CentralAir 1460 non-null object
42 Electrical 1459 non-null object
43 1stFlrSF 1460 non-null int64
44 2ndFlrSF 1460 non-null int64
45 LowQualFinSF 1460 non-null int64
46 GrLivArea 1460 non-null int64
47 BsmtFullBath 1460 non-null int64
48 BsmtHalfBath 1460 non-null int64
49 FullBath 1460 non-null int64
50 HalfBath 1460 non-null int64
51 BedroomAbvGr 1460 non-null int64
52 KitchenAbvGr 1460 non-null int64
53 KitchenQual 1460 non-null object
54 TotRmsAbvGrd 1460 non-null int64
55 Functional 1460 non-null object
56 Fireplaces 1460 non-null int64
57 FireplaceQu 770 non-null object
58 GarageType 1379 non-null object
59 GarageYrBlt 1379 non-null float64
60 GarageFinish 1379 non-null object
61 GarageCars 1460 non-null int64
62 GarageArea 1460 non-null int64
63 GarageQual 1379 non-null object
64 GarageCond 1379 non-null object
65 PavedDrive 1460 non-null object
66 WoodDeckSF 1460 non-null int64
67 OpenPorchSF 1460 non-null int64
68 EnclosedPorch 1460 non-null int64
69 3SsnPorch 1460 non-null int64
70 ScreenPorch 1460 non-null int64
71 PoolArea 1460 non-null int64
72 PoolQC 7 non-null object
73 Fence 281 non-null object
74 MiscFeature 54 non-null object
75 MiscVal 1460 non-null int64
76 MoSold 1460 non-null int64
77 YrSold 1460 non-null int64
78 SaleType 1460 non-null object
79 SaleCondition 1460 non-null object
80 SalePrice 1460 non-null int64

dtypes: float64(3), int64(35), object(43)
memory usage: 924.0+ KB

None
Id MSSubClass MSZoning ... SaleType SaleCondition SalePrice
0 1 60 RL ... WD Normal 208500
1 2 20 RL ... WD Normal 181500
2 3 60 RL ... WD Normal 223500
3 4 70 RL ... WD Abnorml 140000
4 5 60 RL ... WD Normal 250000

[5 rows x 81 columns]

Id MSSubClass ... YrSold SalePrice
count 1460.000000 1460.000000 ... 1460.000000 1460.000000
mean 730.500000 56.897260 ... 2007.815753 180921.195890
std 421.610009 42.300571 ... 1.328095 79442.502883
min 1.000000 20.000000 ... 2006.000000 34900.000000
25% 365.750000 20.000000 ... 2007.000000 129975.000000
50% 730.500000 50.000000 ... 2008.000000 163000.000000
75% 1095.250000 70.000000 ... 2009.000000 214000.000000
99% 1445.410000 190.000000 ... 2010.000000 442567.010000
max 1460.000000 190.000000 ... 2010.000000 755000.000000

[9 rows x 38 columns]

PoolQC 1.00
MiscFeature 0.96
Alley 0.94
Fence 0.81
FireplaceQu 0.47
LotFrontage 0.18
GarageYrBlt 0.06
GarageFinish 0.06
GarageType 0.06
GarageQual 0.06
GarageCond 0.06
BsmtExposure 0.03
BsmtQual 0.03
BsmtCond 0.03
BsmtFinType2 0.03
BsmtFinType1 0.03
MasVnrType 0.01
MasVnrArea 0.01
dtype: float64
LotFrontage 0.18
Alley 0.94
FireplaceQu 0.47
PoolQC 1.00
Fence 0.81
MiscFeature 0.96
dtype: float64
MasVnrType 0.01
MasVnrArea 0.01
BsmtQual 0.03
BsmtCond 0.03
BsmtExposure 0.03
BsmtFinType1 0.03
BsmtFinType2 0.03
GarageType 0.06
GarageYrBlt 0.06
GarageFinish 0.06
GarageQual 0.06
GarageCond 0.06

dtype: float64

YearBuilt YearRemodAdd ... GarageYrBlt_Old YrSold_Old
472 2005 2005 ... 5.0 2
613 2007 2007 ... NaN 3
271 1954 2005 ... 56.0 2
598 1977 1977 ... 33.0 4
1366 1999 1999 ... 11.0 2
1292 1892 1965 ... 25.0 1
705 1930 1950 ... NaN 0
1072 1948 1950 ... 56.0 4
1264 1998 1999 ... 12.0 2
1334 1970 1970 ... 40.0 1

[10 rows x 8 columns]

MSSubClass LotArea ... GarageYrBlt_Old YrSold_Old
count 1460.000000 1460.000000 ... 1460.000000 1460.000000
mean 56.897260 10516.828082 ... 29.691096 2.184247
std 42.300571 9981.264932 ... 25.121824 1.328095
min 20.000000 1300.000000 ... -1.000000 0.000000
25% 20.000000 7553.500000 ... 7.000000 1.000000
50% 50.000000 9478.500000 ... 25.500000 2.000000
75% 70.000000 11601.500000 ... 48.000000 3.000000
max 190.000000 215245.000000 ... 110.000000 4.000000

[8 rows x 35 columns]

(1460, 71)
(1441, 71)

MSZoning LotShape LandContour ... PavedDrive SaleType SaleCondition
0 RL Reg Lvl ... Y WD Normal
1 RL Reg Lvl ... Y WD Normal
2 RL IR1 Lvl ... Y WD Normal
3 RL IR1 Lvl ... Y WD Abnorml
4 RL IR1 Lvl ... Y WD Normal

[5 rows x 36 columns]
LandSlope ExterQual BsmtQual ... GarageCond ExterCond LotShape
0 Gtl Gd Gd ... TA TA Reg
1 Gtl TA Gd ... TA TA Reg
2 Gtl Gd Gd ... TA TA IR1
3 Gtl TA TA ... TA TA IR1
4 Gtl Gd Gd ... TA TA IR1

[5 rows x 15 columns]
LandSlope ExterQual BsmtQual ... GarageCond ExterCond LotShape
0 0 3 4 ... 3 2 3
1 0 2 4 ... 3 2 3
2 0 3 4 ... 3 2 0
3 0 2 3 ... 3 2 0
4 0 3 4 ... 3 2 0

[5 rows x 15 columns]
LandSlope ExterQual BsmtQual ... GarageCond ExterCond LotShape
0 0 3 4 ... 3 2 3
1 0 2 4 ... 3 2 3
2 0 3 4 ... 3 2 0
3 0 2 3 ... 3 2 0
4 0 3 4 ... 3 2 0

[5 rows x 15 columns]
192

0.9126760611261424
0.8742805647415127

[('MSSubClass', -1.363), ('LotArea', 0.046), ('LotShape', 0.171), ('LandSlope', 0.064), ('OverallQual', 0.099), ('OverallCond', 0.083), ('MasVnrArea', 0.067), ('ExterQual', 0.117), ('ExterCond', 0.03), ('BsmtQual', -0.0), ('BsmtCond', 0.088), ('BsmtExposure', 0.0), ('BsmtFinType1', 0.079), ('BsmtFinSF1', -0.007), ('BsmtFinType2', 0.281), ('BsmtFinSF2', -0.057), ('BsmtUnfSF', -0.058), ('TotalBsmtSF', 0.115), ('HeatingQC', 0.07), ('CentralAir', 0.029), ('1stFlrSF', 0.079), ('2ndFlrSF', 0.027), ('LowQualFinSF', 0.031), ('GrLivArea', 0.0), ('BsmtFullBath', 0.087), ('BsmtHalfBath', -0.0), ('FullBath', -0.138), ('HalfBath', 0.135), ('BedroomAbvGr', -0.0), ('KitchenAbvGr', 0.0), ('KitchenQual', 0.0), ('TotRmsAbvGrd', 0.114), ('Fireplaces', 0.235), ('GarageFinish', -0.075), ('GarageCars', -0.037), ('GarageArea', -0.054), ('GarageQual', 0.309), ('GarageCond', 0.492), ('WoodDeckSF', -0.048), ('OpenPorchSF', -0.0), ('EnclosedPorch', 0.144), ('3SsnPorch', 0.336), ('ScreenPorch', 0.0), ('PoolArea', 0.087), ('MiscVal', -0.003), ('YearBuilt_Old', 0.004), ('YearRemodAdd_Old', -0.0), ('GarageYrBlt_Old', 0.001), ('YrSold_Old', -2.107), ('MSZoning_FV', -0.139), ('MSZoning_RH', -0.178), ('MSZoning_RL', 0.127), ('MSZoning_RM', -0.084), ('LandContour_HLS', -0.08), ('LandContour_Low', -0.017), ('LandContour_Lvl', -0.0), ('LotConfig_CulDSac', 0.04), ('LotConfig_FR2', 0.0), ('LotConfig_FR3', 0.0), ('LotConfig_Inside', 0.0), ('Neighborhood_Blueste', -0.0), ('Neighborhood_BrDale', -0.197), ('Neighborhood_BrkSide', -0.0), ('Neighborhood_ClearCr', 1.261), ('Neighborhood_CollgCr', 0.0), ('Neighborhood_Crawfor', 0.192), ('Neighborhood_Edwards', -0.0), ('Neighborhood_Gilbert', 0.033), ('Neighborhood_IDOTRR', -0.109), ('Neighborhood_MeadowV', 0.0), ('Neighborhood_Mitchel', -0.0), ('Neighborhood_NAmes', -0.0), ('Neighborhood_NPkVill', 0.08), ('Neighborhood_NWAmes', 0.0), ('Neighborhood_NoRidge', 0.091), ('Neighborhood_NridgHt', 0.001), ('Neighborhood_OldTown', 0.0), ('Neighborhood_SWISU', 0.086), ('Neighborhood_Sawyer', 0.198), ('Neighborhood_SawyerW', -0.0), ('Neighborhood_Somerst', 0.0), ('Neighborhood_StoneBr', -0.0), ('Neighborhood_Timber', 0.0), ('Neighborhood_Veenker', -0.0), ('Condition1_Feedr', 0.124), ('Condition1_Norm', 0.011), ('Condition1_PosA', -0.0), ('Condition1_PosN', 0.023), ('Condition1_RRAe', -0.0), ('Condition1_RRAn', -0.0), ('Condition1_RRNe', 0.0), ('Condition1_RRNn', -0.0), ('Condition2_Feedr', 0.258), ('Condition2_Norm', 0.0), ('Condition2_PosA', 0.049), ('Condition2_PosN', -0.0), ('Condition2_RRAn', 0.0)]
Fitting 10 folds for each of 7 candidates, totalling 70 fits
mean_fit_time std_fit_time ... mean_train_score std_train_score
0 0.022639 0.003370 ... 0.914561 0.004813
1 0.005884 0.001442 ... 0.864741 0.010531
2 0.004289 0.000898 ... 0.803017 0.010259
3 0.003588 0.000656 ... 0.000000 0.000000
4 0.003493 0.000671 ... 0.000000 0.000000

[5 rows x 31 columns]
{'alpha': 0.001}

0.9126760611261424
0.8742805647415127

Featuere Coef
63 Neighborhood_ClearCr 1.261173
37 GarageCond 0.491839
41 3SsnPorch 0.336091
36 GarageQual 0.308914
14 BsmtFinType2 0.280679
92 Condition2_Feedr 0.258144
32 Fireplaces 0.235348
78 Neighborhood_Sawyer 0.197836
65 Neighborhood_Crawfor 0.192327
2 LotShape 0.171406

0.9190581214891397
0.8631857669259063

Fitting 10 folds for each of 10 candidates, totalling 100 fits
mean_fit_time std_fit_time ... mean_train_score std_train_score
0 0.004391 0.000913 ... 0.921220 0.004914
1 0.003887 0.000832 ... 0.921218 0.004914
2 0.003493 0.000671 ... 0.921078 0.004872
3 0.003690 0.000457 ... 0.920768 0.004801
4 0.003391 0.000662 ... 0.919543 0.004667

[5 rows x 31 columns]
{'alpha': 1.0}

0.9163959190529318
0.869272148885935

Feaure Coef
63 Neighborhood_ClearCr 1.261322
37 GarageCond 0.527510
41 3SsnPorch 0.421265
92 Condition2_Feedr 0.384765
36 GarageQual 0.339885
47 GarageYrBlt_Old 0.298968
32 Fireplaces 0.278424
93 Condition2_Norm 0.278058
22 LowQualFinSF 0.258645
24 BsmtFullBath 0.253544

0.9126760611261424
0.8742805647415127



Image gratuite et libre de droits fournie par pexel.com

Image gratuite et libre de droits fournie par pexel.com

Image gratuite et libre de droits fournie par pexel.com

Image gratuite et libre de droits fournie par pexel.com

Image gratuite et libre de droits fournie par pexel.com

Image gratuite et libre de droits fournie par pexel.com




Régression


Ingénierie des données


Apprentissage profond

Apprentissage automatique












Bienvenu, je m’appelle Eric Soupet et je suis l'administrateur du site elodees.com. elodees.com est un état de l'art de l'Intelligence Artificielle et se veut collaboratif, vous pouvez dès à présent proposer du contenu tels que des articles, des événements, des tutoriels, ... alors n'hésitez pas !

Crédit des images de la plate-forme : Pixabay - Pixabay License | Pexels - Pexels License