<jupyter_start><jupyter_text>Importing Relevant Packages<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Ridge, Lasso, LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error

def regression_metrics(y_true, y_pred):
    rmse = np.sqrt(mean_squared_error(y_true, y_pred))
    rss = np.sum(np.square(y_true - y_pred))
    mae = mean_absolute_error(y_true, y_pred)
    
    metrics = 'RMSE = {}, RSS = {}, MAE = {}'.format(rmse,rss,mae)
    return metrics<jupyter_output><empty_output><jupyter_text>Reading the Dataset<jupyter_code>url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00374/energydata_complete.csv'
df = pd.read_csv(url)
df.head(3)
df.shape
sum(df.isna().sum())
# dropping the lights and date columns
df.drop(columns = ['lights'], inplace=True)
df.drop(columns = ['date'], inplace=True)
scaler = MinMaxScaler()
new_df = pd.DataFrame(scaler.fit_transform(df), columns=df.columns)
new_df.head(2)
new_df.shape
train = new_df.drop(columns=['Appliances'])
target = new_df.Appliances
X_train, X_test, y_train, y_test = train_test_split(train, target, test_size = 0.3, random_state = 42)<jupyter_output><empty_output><jupyter_text>Question 2<jupyter_code>lasso = Lasso(alpha = 0.001)
lasso.fit(X_train, y_train)
len(lasso.coef_)<jupyter_output><empty_output><jupyter_text>Question 6<jupyter_code>lr = LinearRegression()
lr.fit(X_train, y_train)
y_pred_linear = lr.predict(X_test)
regression_metrics(y_test, y_pred_linear)<jupyter_output><empty_output><jupyter_text>Question 8<jupyter_code>lr.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>Question 10<jupyter_code>regression_metrics(y_test, y_pred_linear)<jupyter_output><empty_output><jupyter_text>Question 11<jupyter_code>y_pred_lasso = lasso.predict(X_test)
regression_metrics(y_test, y_pred_lasso)<jupyter_output><empty_output><jupyter_text>Question 13<jupyter_code>ridge = Ridge(alpha = 0.4)
ridge.fit(X_train, y_train)
y_pred_ridge = ridge.predict(X_test)
regression_metrics(y_test, y_pred_ridge)<jupyter_output><empty_output><jupyter_text>There's a difference between rmse of Ridge(alpha=0.4) and LinearRegression models but a very small one that can be ignored  Question 17<jupyter_code>regression_metrics(y_test, y_pred_linear)<jupyter_output><empty_output><jupyter_text>Question 18<jupyter_code>round(lr.score(X_test, y_test), 2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11468423091824874, 'fraction_numerical': 0.012785741960480435, 'mean_word_length': 9.007751937984496, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '80613', 'license': 'MIT', 'n_tokens_mistral': 1020, 'n_tokens_neox': 974, 'n_words': 151, 'path': 'stage-2.ipynb', 'repo_name': 'KolatimiDave/Hamoye', 'size': '2581'}