Introduction machine-learning with python library Scikit-learn with example
Machine learning with Python Scikit-Learn #Introduction machine-learning with python library Scikit-learn with example
Machine learning is a branch of artificial intelligence that aims to understand how humans learn and develop strategies to replicate that process using data and algorithms. These techniques typically fall into three primary learning categories:
Data processing is a critical step in the machine learning workflow, as real-world data can be messy and may contain:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn
# Load dataset
df = pd.read_csv('hiring.csv')
df.isnull().sum()
# Handling missing values
df['test_score(out of 10)'].fillna(df['test_score(out of 10)'].mean(), inplace=True)
df['experience'].fillna(0, inplace=True)
def stringToNum(word):
mapping = {'zero': 0, 'one': 1, 'five': 5, 'two': 2,
'seven': 7, 'three': 3, 'ten': 10, 'eleven': 11, 0: 0}
return mapping[word]
df['experience'] = df['experience'].apply(lambda x: stringToNum(x))
# Splitting dataset
x = df.iloc[:, :3]
y = df.iloc[:, -1]
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1, random_state=5)
# Building a Linear Regression model
from sklearn.linear_model import LinearRegression
mymodel = LinearRegression()
mymodel.fit(x_train, y_train)
# Making predictions
y_pred = mymodel.predict(x_test)
y = mymodel.predict([[5, 8, 7]])
# Saving model
import pickle
pickle.dump(mymodel, open("model.pkl", "wb"))
Clustering is an unsupervised learning technique used to group similar data points based on certain characteristics.
n
data points into k
clusters based on feature similarity.Scikit-Learn provides a wide range of machine learning models, preprocessing tools, and assessment metrics to streamline the development of predictive models. By mastering these techniques, data scientists can extract meaningful insights and improve decision-making processes.
For more advanced machine learning tutorials, stay updated with our latest content.