0% found this document useful (0 votes)
2 views4 pages

ML and DL

The document provides notes on various machine learning (ML) and deep learning (DL) algorithms, including Linear Regression, Logistic Regression, Decision Trees, Random Forest, K-Nearest Neighbors, Support Vector Machine, Naive Bayes, K-Means Clustering, Principal Component Analysis, and Neural Networks. Each algorithm is accompanied by a brief description and a Python code example demonstrating its implementation. The notes serve as a comprehensive guide for understanding and applying these algorithms in Python.

Uploaded by

duddulapranathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

ML and DL

The document provides notes on various machine learning (ML) and deep learning (DL) algorithms, including Linear Regression, Logistic Regression, Decision Trees, Random Forest, K-Nearest Neighbors, Support Vector Machine, Naive Bayes, K-Means Clustering, Principal Component Analysis, and Neural Networks. Each algorithm is accompanied by a brief description and a Python code example demonstrating its implementation. The notes serve as a comprehensive guide for understanding and applying these algorithms in Python.

Uploaded by

duddulapranathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Complete ML & DL Algorithms Notes with Python Code

1. Linear Regression

Used for predicting continuous values like house price, sales, temperature, etc.

Python Code Example:

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression

area = np.array([1000, 1500, 2000, 2500, 3000]).reshape(-1,1)


price = np.array([200000, 300000, 400000, 500000, 600000])
model = LinearRegression()
model.fit(area, price)
predicted_price = model.predict([[2200]])
print(f"Predicted Price: INR {predicted_price[0]}")

2. Logistic Regression

Used for binary classification problems (Yes/No, True/False).

Python Code Example:

from sklearn.linear_model import LogisticRegression

model = LogisticRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print("Accuracy:", model.score(X_test, y_test))

3. Decision Tree

Used for classification and regression tasks by splitting data into decision nodes.
Complete ML & DL Algorithms Notes with Python Code

Python Code Example:

from sklearn.tree import DecisionTreeClassifier

model = DecisionTreeClassifier()
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))

4. Random Forest

An ensemble technique that combines multiple decision trees for improved accuracy.

Python Code Example:

from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))

5. K-Nearest Neighbors (KNN)

Classifies a new point based on majority vote of K nearest neighbors.

Python Code Example:

from sklearn.neighbors import KNeighborsClassifier

model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))
Complete ML & DL Algorithms Notes with Python Code

6. Support Vector Machine (SVM)

Finds the best hyperplane to separate data points in classification problems.

Python Code Example:

from sklearn.svm import SVC

model = SVC(kernel='linear')
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))

7. Naive Bayes

A probabilistic classifier based on Bayes' theorem assuming feature independence.

Python Code Example:

from sklearn.naive_bayes import GaussianNB

model = GaussianNB()
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))

8. K-Means Clustering

Used for clustering similar data points into K groups.

Python Code Example:

from sklearn.cluster import KMeans


Complete ML & DL Algorithms Notes with Python Code

kmeans = KMeans(n_clusters=3)
kmeans.fit(X_train)
print("Cluster Centers:", kmeans.cluster_centers_)

9. Principal Component Analysis (PCA)

Dimensionality reduction technique that preserves variance.

Python Code Example:

from sklearn.decomposition import PCA

pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_train)
print("Explained Variance Ratio:", pca.explained_variance_ratio_)

10. Neural Networks (Deep Learning)

Multi-layer perceptron using Keras for classification tasks.

Python Code Example:

from keras.models import Sequential


from keras.layers import Dense

model = Sequential()
model.add(Dense(10, input_dim=4, activation='relu'))
model.add(Dense(3, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

You might also like