Skip to content

Instantly share code, notes, and snippets.

Avatar

Aniruddha Bhandari aniruddha27

View GitHub Profile
View matplotlib1.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn')
View Multicollinearity_VIF.py
# 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])]
View Multicollinearity_VIF_Join.py
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)
View Linear regression model.py
#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))
View Ridge regression model.py
#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))
View Lasso regression model.py
#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))
View Matplotlib_meal_dataframe.py
df_meal = pd.read_csv('C:\\Users\Dell\\Desktop\\train_food\\meal_info.csv')
df_meal.head()
View Matplotlib_fulfillment_center_dataframe.py
df_center = pd.read_csv('C:\\Users\Dell\\Desktop\\train_food\\fulfilment_center_info.csv')
df_center.head()