This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.style.use('seaborn') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import library for VIF | |
from statsmodels.stats.outliers_influence import variance_inflation_factor | |
def calc_vif(X): | |
# Calculating VIF | |
vif = pd.DataFrame() | |
vif["variables"] = X.columns | |
vif["VIF"] = [variance_inflation_factor(X.values, i) for i in range(X.shape[1])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = df.iloc[:,:-1] | |
calc_vif(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = df.drop(['Age','Salary'],axis=1) | |
calc_vif(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df2 = df.copy() | |
df2['Age_at_joining'] = df.apply(lambda x: x['Age'] - x['Years of service'],axis=1) | |
X = df2.drop(['Age','Years of service','Salary'],axis=1) | |
calc_vif(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import linear regression | |
from sklearn.linear_model import LinearRegression | |
#fit on training data | |
lr=LinearRegression() | |
lr.fit(X_train,y_train) | |
#accuracy | |
print('Training accuracy =',lr.score(X_train,y_train)) | |
print('Testing accuracy =',lr.score(X_test,y_test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import ridge model | |
from sklearn.linear_model import Ridge | |
#fit on training data with regularization of 0.3 | |
ridge = Ridge(alpha = 0.3) | |
ridge.fit(X_train,y_train) | |
#accuracy | |
print('Train',ridge.score(X_train,y_train)) | |
print('Test',ridge.score(X_test,y_test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import lasso | |
from sklearn.linear_model import Lasso | |
#fit on training dataset | |
ls = Lasso(alpha=0.08) | |
ls.fit(X_train, y_train) | |
#accuracy | |
print('Training score =', ls.score(X_train, y_train)) | |
print('Testing score=', ls.score(X_test, y_test)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_meal = pd.read_csv('C:\\Users\Dell\\Desktop\\train_food\\meal_info.csv') | |
df_meal.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_center = pd.read_csv('C:\\Users\Dell\\Desktop\\train_food\\fulfilment_center_info.csv') | |
df_center.head() |
OlderNewer