0% found this document useful (0 votes)
3 views

Machine Learning with Scikit-Learn

Scikit-Learn is a widely used Python library for machine learning that provides tools for data preprocessing, model selection, and evaluation. The document outlines the installation process, data preparation, feature scaling, training a linear regression model, and evaluating the model's performance using mean squared error. It concludes by highlighting Scikit-Learn's role in simplifying machine learning tasks.

Uploaded by

22bph016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Machine Learning with Scikit-Learn

Scikit-Learn is a widely used Python library for machine learning that provides tools for data preprocessing, model selection, and evaluation. The document outlines the installation process, data preparation, feature scaling, training a linear regression model, and evaluating the model's performance using mean squared error. It concludes by highlighting Scikit-Learn's role in simplifying machine learning tasks.

Uploaded by

22bph016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Machine Learning with Scikit-Learn

Introduction

Scikit-Learn is a popular Python library for machine learning, offering tools for data
preprocessing, model selection, and evaluation.

Installing Scikit-Learn
pip install scikit-learn

Importing Required Libraries


import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

Data Preparation
data = {'Experience': [1, 2, 3, 4, 5], 'Salary': [30000, 35000, 40000, 45000, 50000]}
df = pd.DataFrame(data)
X = df[['Experience']]
y = df['Salary']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Feature Scaling
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

Training a Linear Regression Model


model = LinearRegression()
model.fit(X_train_scaled, y_train)
predictions = model.predict(X_test_scaled)

Model Evaluation
mse = mean_squared_error(y_test, predictions)
print("Mean Squared Error:", mse)

Conclusion

Scikit-Learn simplifies machine learning implementation. Next, we explore Python for


Computational Physics (Solving PDEs with PINNs).

You might also like