Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Lasso
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error
# Load your dataset from the CSV file
file_path = "C:/Users/wilso/OneDrive/Desktop/uk_renewable_energy.csv"
df = pd.read_csv(file_path)
X = df.drop('CO AQI Value', axis=1)
y = df['Ozone AQI Value']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Standardize the features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Create and train the LASSO regression model
alpha_value = 0.01 # Adjust this value to control the strength of regularization
lasso_model = Lasso(alpha=alpha_value)
lasso_model.fit(X_train_scaled, y_train)
# Make predictions on the test set
y_pred = lasso_model.predict(X_test_scaled)
# Evaluate the model
mse = mean_squared_error(y_test, y_pred)
print(f'Mean Squared Error: {mse}')
# Display the coefficients of the features
coefficients = lasso_model.coef_
print('LASSO Coefficients:')
for feature, coef in zip(X.columns, coefficients):
print(f'{feature}: {coef}')