Machine Learning Algorithms Archives - Indian AI Production https://indianaiproduction.com/machine-learning-algorithms/ Artificial Intelligence Education Free for Everyone Sat, 01 Aug 2020 06:40:21 +0000 en-US hourly 1 https://i0.wp.com/indianaiproduction.com/wp-content/uploads/2019/06/Channel-logo-in-circle-473-x-472-px.png?fit=32%2C32&ssl=1 Machine Learning Algorithms Archives - Indian AI Production https://indianaiproduction.com/machine-learning-algorithms/ 32 32 163118462 Naïve Bayes Classifier Algorithm Theorem Explained in Detail https://indianaiproduction.com/naive-bayes-classifer/ https://indianaiproduction.com/naive-bayes-classifer/#respond Sat, 01 Aug 2020 06:40:17 +0000 https://indianaiproduction.com/?p=1583 In this ML Algorithms course tutorial, we are going to learn “Naïve Bayes Classifier in detail. we covered it by practically and theoretical intuition. What is the naive Bayes classifier algorithm? What is Naïve Bayes Classifier used for? How do Naïve Bayes Classifier work? What is Naïve in Naïve Bayes Classifier? Maths behind Naïve Bayes …

Naïve Bayes Classifier Algorithm Theorem Explained in Detail Read More »

The post Naïve Bayes Classifier Algorithm Theorem Explained in Detail appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Naïve Bayes Classifier in detail. we covered it by practically and theoretical intuition.

  1. What is the naive Bayes classifier algorithm?
  2. What is Naïve Bayes Classifier used for?
  3. How do Naïve Bayes Classifier work?
  4. What is Naïve in Naïve Bayes Classifier?
  5. Maths behind Naïve Bayes Classifier?
  6. What are the advantages & disadvantages of naive Bayes classifier?
  7. How to implement Naïve Bayes Classifier in python using sklearn?
Naive Bayes Classifier

Naïve Bayes Classifier Project

"""
## Naive Bayes Classifier

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train Naive Bayes Classifier Model"""

from sklearn.naive_bayes import GaussianNB

classifier = GaussianNB()
classifier.fit(X_train, y_train)

classifier.score(X_test, y_test)

from sklearn.naive_bayes import MultinomialNB
classifier_m = MultinomialNB()
classifier_m.fit(X_train, y_train)

classifier_m.score(X_test, y_test)

from sklearn.naive_bayes import BernoulliNB
classifier_b = BernoulliNB()
classifier_b.fit(X_train, y_train)

classifier_b.score(X_test, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1 = np.array([patient1])
patient1

classifier.predict(patient1)

data.target_names

pred = classifier.predict(patient1)

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')

"""Ab milenge next tutorial me,Tab tak ke liye SIKHATE SIKHATE kuch IMPLEMENT karte raho, Thank You.....-:)"""

The post Naïve Bayes Classifier Algorithm Theorem Explained in Detail appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/naive-bayes-classifer/feed/ 0 1583
K Nearest Neighbor Regression Algorithm Explain with Project https://indianaiproduction.com/k-nearest-neighbor-regression/ https://indianaiproduction.com/k-nearest-neighbor-regression/#respond Mon, 20 Jul 2020 04:17:00 +0000 https://indianaiproduction.com/?p=1563 In this ML Algorithms course tutorial, we are going to learn “ K Nearest Neighbor Regression in detail. we covered it by practically and theoretical intuition. What is K Nearest Neighbor? What does the K stand for in K nearest neighbors? What is K Nearest Neighbor used for? How do K Nearest Neighbor work? What …

K Nearest Neighbor Regression Algorithm Explain with Project Read More »

The post K Nearest Neighbor Regression Algorithm Explain with Project appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “ K Nearest Neighbor Regression in detail. we covered it by practically and theoretical intuition.

  1. What is K Nearest Neighbor?
  2. What does the K stand for in K nearest neighbors?
  3. What is K Nearest Neighbor used for?
  4. How do K Nearest Neighbor work?
  5. What is K Nearest Neighbor Regression?
  6. What is Euclidian Distance Manhattan Distance?
  7. What is nearest Neighbour rule?
  8. What is K Nearest Neighbor Regression diagram?
  9. How to implement K Nearest Neighbor Regression in python using sklearn?
k Nearest Neighbor Regression

K Nearest Neighbor Regression Project

"""
## Business Problem - Predict the Price of Bangalore House

**Using** K Nearest Neighbor Regression - Supervised Machine Learning Algorithm

### Load Libraries
"""

import pandas as pd

"""### Load Data"""

path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" 
df = pd.read_csv(path)

df.head()

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""##K Nearest Neighbor Regression - ML Model Training"""

from sklearn.neighbors import KNeighborsRegressor

regressor = KNeighborsRegressor(n_neighbors=5)
regressor.fit(X_train, y_train)

regressor.score(X_test, y_test)

"""## Predict the value of Home"""

X_test.iloc[-1, :]

regressor.predict([X_test.iloc[-1, :]])

y_test.iloc[-1]

y_pred = regressor.predict(X_test)
y_pred

y_test


The post K Nearest Neighbor Regression Algorithm Explain with Project appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/k-nearest-neighbor-regression/feed/ 0 1563
K Nearest Neighbor Classification Algorithm Explain with Project https://indianaiproduction.com/k-nearest-neighbor-classification/ https://indianaiproduction.com/k-nearest-neighbor-classification/#respond Sun, 19 Jul 2020 04:58:47 +0000 https://indianaiproduction.com/?p=1558 In this ML Algorithms course tutorial, we are going to learn “ K Nearest Neighbor Classification in detail. we covered it by practically and theoretical intuition. What is K Nearest Neighbor? What does the K stand for in K nearest neighbors? What is K Nearest Neighbor used for? How do K Nearest Neighbor work? What …

K Nearest Neighbor Classification Algorithm Explain with Project Read More »

The post K Nearest Neighbor Classification Algorithm Explain with Project appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “ K Nearest Neighbor Classification in detail. we covered it by practically and theoretical intuition.

  1. What is K Nearest Neighbor?
  2. What does the K stand for in K nearest neighbors?
  3. What is K Nearest Neighbor used for?
  4. How do K Nearest Neighbor work?
  5. What is K Nearest Neighbor Classification?
  6. What is Euclidian Distance Manhattan Distance?
  7. What is nearest Neighbour rule?
  8. What is K Nearest Neighbor Classification diagram?
  9. How to implement K Nearest Neighbor Classification in python using sklearn?
k nearest neighbor

K Nearest Neighbor Classification (KNN) Project

# -*- coding: utf-8 -*-
"""K Nearest Neighbor Classification.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1MgSgP5NhZjoyX3vQSXpd_hq2GFqD4hbp

# K Nearest Neighbor Classification

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train K Nearest Neighbo[link text](https://)r Classification Model

> Indented block
"""

from sklearn.neighbors import KNeighborsClassifier

classifier = KNeighborsClassifier(n_neighbors=5)
classifier.fit(X_train, y_train)

classifier.score(X_test, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1 = np.array([patient1])

patient1

classifier.predict(patient1)

pred = classifier.predict(patient1)

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')

The post K Nearest Neighbor Classification Algorithm Explain with Project appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/k-nearest-neighbor-classification/feed/ 0 1558
Save & Load Machine Learning Model using Pickle & Joblib https://indianaiproduction.com/save-and-load-machine-learning-model/ https://indianaiproduction.com/save-and-load-machine-learning-model/#respond Fri, 17 Jul 2020 05:18:26 +0000 https://indianaiproduction.com/?p=1553 In this ML Algorithms course tutorial, we are going to learn “How to save machine learning Model in detail. we covered it by practically and theoretical intuition. How do you save a ML model? How can we save the machine learning model? How do you pickle a machine learning model? Where are machine learning models …

Save & Load Machine Learning Model using Pickle & Joblib Read More »

The post Save & Load Machine Learning Model using Pickle & Joblib appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “How to save machine learning Model in detail. we covered it by practically and theoretical intuition.

  1. How do you save a ML model?
  2. How can we save the machine learning model?
  3. How do you pickle a machine learning model?
  4. Where are machine learning models stored?
  5. What is Joblib file?
  6. How do I load a python model?
  7. What is model in python?
  8. What is serialization in python?
  9. How do you deploy ML models in production?
save machine learning model

How to Save & Load Machine Learning Model

# -*- coding: utf-8 -*-
"""Save Model.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1BNLslMmXZ00oP-fCL9eD_3owzsY5zp7G

##Random Forest Classification

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train Random Forest Classification Model"""

from sklearn.ensemble import RandomForestClassifier

classifier = RandomForestClassifier(n_estimators=100, criterion='gini')
classifier.fit(X_train, y_train)

classifier.score(X_test, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1 = np.array([patient1])
patient1

classifier.predict(patient1)

data.target_names

pred = classifier.predict(patient1)

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')

"""# Save Model

## Save Model using Pickle
"""

import pickle

pickle.dump(classifier, open('model_save', 'wb'))

model = pickle.load(open('model_save', 'rb'))

model.predict(patient1)[0]

"""## Save Model using Joblib"""

import joblib

joblib.dump(classifier, 'model_save2')

model2 = joblib.load('model_save2')

model2.predict(patient1)


The post Save & Load Machine Learning Model using Pickle & Joblib appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/save-and-load-machine-learning-model/feed/ 0 1553
Random Forest Regression Algorithm Explain with Project https://indianaiproduction.com/random-forest-regression/ https://indianaiproduction.com/random-forest-regression/#respond Thu, 16 Jul 2020 05:29:09 +0000 https://indianaiproduction.com/?p=1546 In this ML Algorithms course tutorial, we are going to learn “Random Forest Regression in detail. we covered it by practically and theoretical intuition. What is Random Forest? What is Random Forest used for? How do Random Forest work? What is Random Forest Regression? What is Gini impurity, entropy, cost function for CART algorithm? What …

Random Forest Regression Algorithm Explain with Project Read More »

The post Random Forest Regression Algorithm Explain with Project appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Random Forest Regression in detail. we covered it by practically and theoretical intuition.

  1. What is Random Forest?
  2. What is Random Forest used for?
  3. How do Random Forest work?
  4. What is Random Forest Regression?
  5. What is Gini impurity, entropy, cost function for CART algorithm?
  6. What is Random Forest diagram?
  7. What is the difference between decision tree and random forest?
  8. How to implement Random Forest Regression in python using sklearn?

Random Forest Project Source Code

# -*- coding: utf-8 -*-
"""Random Forest Regression.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1X0LsHDOtyFeIN266qfVrOFXDrkJ5ESU3

## Business Problem - Predict the Price of Bangalore House

Using Randome Forest Regression - Supervised Machine Learning Algorithm

### Load Libraries
"""

import pandas as pd

"""### Load Data"""

path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" 
df = pd.read_csv(path)

df.head()

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""##Randome Forest Regression - ML Model Training"""

from sklearn.ensemble import RandomForestRegressor

regressor = RandomForestRegressor(n_estimators=100, criterion='mse')
regressor.fit(X_train, y_train)

regressor.score(X_test, y_test)

regressor_100 = RandomForestRegressor(n_estimators=500, criterion='mse')
regressor_100.fit(X_train, y_train)

regressor_100.score(X_test, y_test)

"""## Predict the value of Home"""

X_test.iloc[-1, :]

regressor.predict([X_test.iloc[-1, :]])

y_test.iloc[-1]

y_pred = regressor.predict(X_test)
y_pred

y_test

The post Random Forest Regression Algorithm Explain with Project appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/random-forest-regression/feed/ 0 1546
Random Forest Classification Algorithm Explain with Project https://indianaiproduction.com/random-forest-classification/ https://indianaiproduction.com/random-forest-classification/#respond Wed, 15 Jul 2020 06:28:18 +0000 https://indianaiproduction.com/?p=1541 In this ML Algorithms course tutorial, we are going to learn “Random Forest Classification in detail. we covered it by practically and theoretical intuition. What is the Random Forest? What is Random Forest used for? How does Random Forest work? What is the Random Forest Classification? What is Gini impurity, entropy, the cost function for …

Random Forest Classification Algorithm Explain with Project Read More »

The post Random Forest Classification Algorithm Explain with Project appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Random Forest Classification in detail. we covered it by practically and theoretical intuition.

  1. What is the Random Forest?
  2. What is Random Forest used for?
  3. How does Random Forest work?
  4. What is the Random Forest Classification?
  5. What is Gini impurity, entropy, the cost function for the CART algorithm?
  6. What is the Random Forest diagram?
  7. What is the difference between a decision tree and random forest?
  8. How to implement Random Forest Classification in python using sklearn?

Random Forest Classification Implementation

# -*- coding: utf-8 -*-
"""Random Forest  Classification.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/13nr6Ix-AQ3B2vbcwr7E18kXalX_hTKYA

##Random Forest Classification

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train Random Forest Classification Model"""

from sklearn.ensemble import RandomForestClassifier

classifier = RandomForestClassifier(n_estimators=100, criterion='gini')
classifier.fit(X_train, y_train)

classifier.score(X_test, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1 = np.array([patient1])
patient1

classifier.predict(patient1)

data.target_names

pred = classifier.predict(patient1)

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')


The post Random Forest Classification Algorithm Explain with Project appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/random-forest-classification/feed/ 0 1541
Decision Tree Regression | Machine Learning Algorithm https://indianaiproduction.com/decision-tree-regression/ https://indianaiproduction.com/decision-tree-regression/#respond Tue, 14 Jul 2020 05:38:12 +0000 https://indianaiproduction.com/?p=1536 In this ML Algorithms course tutorial, we are going to learn “Decision Tree Regression in detail. we covered it by practically and theoretical intuition. What is Decision Tree? What are decision trees used for? How do Decision trees work? What is Decision Tree Regression? What is Gini impurity, entropy, cost function for CART algorithm? What …

Decision Tree Regression | Machine Learning Algorithm Read More »

The post Decision Tree Regression | Machine Learning Algorithm appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Decision Tree Regression in detail. we covered it by practically and theoretical intuition.

  1. What is Decision Tree?
  2. What are decision trees used for?
  3. How do Decision trees work?
  4. What is Decision Tree Regression?
  5. What is Gini impurity, entropy, cost function for CART algorithm?
  6. What is decision tree diagram?
  7. What is the difference between decision tree and random forest?
  8. How to implement Decision Tree Regression in python using sklearn?

Decision Tree Regression Source Code

# -*- coding: utf-8 -*-
"""Decision Tree Regression.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1-P0w3bewXTLPItdgVatdg8i5SzlIDX-L

## Business Problem - Predict the Price of Bangalore House

Using Decision Tree Regression - Supervised Machine Learning Algorithm

### Load Libraries
"""

import pandas as pd

"""### Load Data"""

path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" 
df = pd.read_csv(path)

df.head()

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""##Decision Tree Regression - ML Model Training"""

from sklearn.tree import DecisionTreeRegressor

regressor = DecisionTreeRegressor(criterion='mse')
regressor.fit(X_train, y_train)

regressor.score(X_test, y_test)

"""## Predict the value of Home"""

X_test.iloc[-1, :]

regressor.predict([X_test.iloc[-1, :]])

y_test.iloc[-1]

pred = regressor.predict(X_test)
pred

y_test

"""Ab milenge next tutorial me,Tab tak ke liye SIKHATE SIKHATE kuch IMPLEMENT karte raho, Thank You.....-:)"""

The post Decision Tree Regression | Machine Learning Algorithm appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/decision-tree-regression/feed/ 0 1536
Decision Tree Classification Algorithm | Machine Learning https://indianaiproduction.com/decision-tree-classification/ https://indianaiproduction.com/decision-tree-classification/#comments Mon, 13 Jul 2020 13:04:46 +0000 https://indianaiproduction.com/?p=1532 In this ML Algorithms course tutorial, we are going to learn “Decision Tree Classification in detail. we covered it by practically and theoretical intuition. What is Decision Tree? What are the decision trees used for? How do Decision trees work? What is Decision Tree Classification? What is Gini impurity, entropy, the cost function for the …

Decision Tree Classification Algorithm | Machine Learning Read More »

The post Decision Tree Classification Algorithm | Machine Learning appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Decision Tree Classification in detail. we covered it by practically and theoretical intuition.

  1. What is Decision Tree?
  2. What are the decision trees used for?
  3. How do Decision trees work?
  4. What is Decision Tree Classification?
  5. What is Gini impurity, entropy, the cost function for the CART algorithm?
  6. What is decision tree diagram?
  7. What is the difference between a decision tree and random forest?
  8. How to implement Decision Tree Classification in python using sklearn?

Decision Tree Classifier Source Code

# -*- coding: utf-8 -*-
"""Decision Tree Classification.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1H1XImaclUxhA9W2nETUTclNeERJnuU5W

## Decision Tree Classification

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train Decision Tree Classification Model"""

from sklearn.tree import DecisionTreeClassifier

classifier = DecisionTreeClassifier(criterion='gini')
classifier.fit(X_train, y_train)

classifier.score(X_test, y_test)

classifier_entropy = DecisionTreeClassifier(criterion='entropy')
classifier_entropy.fit(X_train, y_train)

classifier_entropy.score(X_test, y_test)

"""## Feature Scaling"""

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()

sc.fit(X_train)

X_train_sc = sc.transform(X_train)
X_test_sc = sc.transform(X_test)

classifier_sc = DecisionTreeClassifier(criterion='gini')
classifier_sc.fit(X_train_sc, y_train)

classifier_sc.score(X_test_sc, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1 = np.array([patient1])
patient1

classifier.predict(patient1)

data.target_names

pred = classifier.predict(patient1)

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')

The post Decision Tree Classification Algorithm | Machine Learning appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/decision-tree-classification/feed/ 1 1532
Support Vector Machine (SVM) Classification Algorithm | Machine Learning Algorithm https://indianaiproduction.com/support-vector-machine/ https://indianaiproduction.com/support-vector-machine/#respond Sun, 12 Jul 2020 04:40:27 +0000 https://indianaiproduction.com/?p=1528 In this ML Algorithms course tutorial, we are going to learn “Support Vector Machine Classifier in detail. we covered it by practically and theoretical intuition. What is Linear Support Vector Classifier? What is Non-Linear Support Vector Classifier? How to implement Support Vector Classifier in python? Support Vector Classification Practical Code

The post Support Vector Machine (SVM) Classification Algorithm | Machine Learning Algorithm appeared first on Indian AI Production.

]]>
In this ML Algorithms course tutorial, we are going to learn “Support Vector Machine Classifier in detail. we covered it by practically and theoretical intuition.

  1. What is Linear Support Vector Classifier?
  2. What is Non-Linear Support Vector Classifier?
  3. How to implement Support Vector Classifier in python?

Support Vector Classification Practical Code

# -*- coding: utf-8 -*-
"""support vector classification.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1apM2WDL3ejysFr3C-Zr44eB8on8lFa-2

#Support Vector Classification

### Import Libraries
"""

# import libraries
import numpy as np
import pandas as pd

"""### Load Dataset"""

#load dataset
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()

data.data

data.feature_names

data.target

data.target_names

# create dtaframe
df = pd.DataFrame(np.c_[data.data, data.target], columns=[list(data.feature_names)+['target']])
df.head()

df.tail()

df.shape

"""### Split Data"""

X = df.iloc[:, 0:-1]
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.2, random_state=2020)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Train Support Vector Classification Model"""

from sklearn.svm import SVC

classification_rbf = SVC(kernel='rbf')
classification_rbf.fit(X_train, y_train)

classification_rbf.score(X_test, y_test)

"""## Feature Scaling"""

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()

sc.fit(X_train)

X_train_sc = sc.transform(X_train)
X_test_sc = sc.transform(X_test)

classification_rbf_2 = SVC(kernel='rbf')
classification_rbf_2.fit(X_train_sc, y_train)

classification_rbf_2.score(X_test_sc, y_test)

"""## SVC with kernel Polynomial"""

classification_poly = SVC(kernel='poly', degree=2)
classification_poly.fit(X_train_sc, y_train)

classification_poly.score(X_test_sc, y_test)

"""## SVC with Kernel Linear"""

classification_linear = SVC(kernel='linear')
classification_linear.fit(X_train_sc, y_train)

classification_linear.score(X_test_sc, y_test)

"""## Predict Cancer"""

patient1 = [17.99,
 10.38,
 122.8,
 1001.0,
 0.1184,
 0.2776,
 0.3001,
 0.1471,
 0.2419,
 0.07871,
 1.095,
 0.9053,
 8.589,
 153.4,
 0.006399,
 0.04904,
 0.05373,
 0.01587,
 0.03003,
 0.006193,
 25.38,
 17.33,
 184.6,
 2019.0,
 0.1622,
 0.6656,
 0.7119,
 0.2654,
 0.4601,
 0.1189]

patient1_sc = sc.transform(np.array([patient1]))
patient1_sc

pred= classification_linear.predict(patient1_sc)
pred

data.target_names

if pred[0] == 0:
  print('Patient has Cancer (malignant tumor)')
else:
  print('Patient has no Cancer (malignant benign)')

"""Ab milenge next tutorial me,Tab tak ke liye SIKHATE SIKHATE kuch IMPLEMENT karte raho, Thank You.....-:)"""

The post Support Vector Machine (SVM) Classification Algorithm | Machine Learning Algorithm appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/support-vector-machine/feed/ 0 1528
Support Vector Regression Algorithm | Machine Learning Algorithm Tutorial https://indianaiproduction.com/support-vector-regression/ https://indianaiproduction.com/support-vector-regression/#comments Wed, 01 Jul 2020 02:43:40 +0000 https://indianaiproduction.com/?p=1506 In this ML Algorithms course tutorial, we are going to learn “Support Vector Regression in detail. we covered it by practically and theoretical intuition. What is Linear Support Vector Regression? What is Non-Linear Support Vector Regression? How to implement Support Vector Regression in python? Practical Source Code To learn more about Support Vector Regression: Click …

Support Vector Regression Algorithm | Machine Learning Algorithm Tutorial Read More »

The post Support Vector Regression Algorithm | Machine Learning Algorithm Tutorial appeared first on Indian AI Production.

]]>

In this ML Algorithms course tutorial, we are going to learn “Support Vector Regression in detail. we covered it by practically and theoretical intuition.

  1. What is Linear Support Vector Regression?
  2. What is Non-Linear Support Vector Regression?
  3. How to implement Support Vector Regression in python?

Practical Source Code

# -*- coding: utf-8 -*-
"""Support Vector Regression Bangalore -  House Price Prediction.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1Wm2WonoKBMBzDfdo56ALEN5ugRZcA_gn

## Business Problem - Predict the Price of Bangalore House

Using Support Vector Regression - Supervised Machine Learning Algorithm

### Load Libraries
"""

import pandas as pd

"""### Load Data"""

path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" 
df = pd.read_csv(path)

df.head()

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""## Feature Scaling"""

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train = sc.transform(X_train)
X_test = sc.transform(X_test)

"""## Support Vector Regression - ML Model Training"""

from sklearn.svm import SVR

svr_rbf = SVR(kernel='rbf')
svr_rbf.fit(X_train, y_train)
svr_rbf.score(X_test, y_test)

svr_linear = SVR(kernel='linear')
svr_linear.fit(X_train, y_train)
svr_linear.score(X_test, y_test)

svr_poly = SVR(kernel='poly',degree=2,)
svr_poly.fit(X_train, y_train)
svr_poly.score(X_test, y_test)

"""## Predict the value of Home and Test"""

X_test[0]

svr_linear.predict([X_test[0]])

y_pred = svr_linear.predict(X_test)
y_pred

y_test

from sklearn.metrics import mean_squared_error
import numpy as np

mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)

print('MSE = ', mse)
print('RMSE = ', rmse)

#End

To learn more about Support Vector Regression: Click Here

The post Support Vector Regression Algorithm | Machine Learning Algorithm Tutorial appeared first on Indian AI Production.

]]>
https://indianaiproduction.com/support-vector-regression/feed/ 1 1506