which is best python modules for machine learning
A module is a file in Python which organizes code in a systematic manner in order to increase our understanding and accessibility of the code. This code mostly consists of…
A module is a file in Python which organizes code in a systematic manner in order to increase our understanding and accessibility of the code. This code mostly consists of…
Tree is a type of DataStructure, consisting mainly of nodes. Every node has some child node until we reach the last node having no childrens. Those last nodes are called…
Introduction : Hey guys, in this article i am share my one internship Machine learning project code, which is Prediction using Supervised Machine Learning Algorithms. so let's see : Prediction…
k means clustering algorithm python example K Means Clustering is unsupervised learning algorithm in python (i.e.it's tries to cluster the different data based on their similarity) and another meaning is…
Welcome everyone, Today we will see Decision Trees and Random Forests classifier-and Types in Python so let’s start:
Import Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
Get the Data
df = pd.read_csv('Decision Trees.csv')
df.head()
Decision Age Number Start
0 present 34 3 9
1 absent 58 4 15
2 absent 28 5 8
3 present 72 3 4
4 absent 81 4 15
Let’s start to split up the data into a training and test set.
from sklearn.model_selection import train_test_split
x = df.drop('Decision Trees',axis=1)
y = df['Decision Trees']
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.20)
We will start just by training a single decision trees in this section.
from sklearn.tree import DecisionTreeClassifier
dtree = DecisionTreeClassifier()
dtree.fit(x_train,y_train)
DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
max_features=None, max_leaf_nodes=None, min_samples_leaf=1,
min_samples_split=2, min_weight_fraction_leaf=0.0,
presort=False, random_state=None, splitter='best')
How to Prediction and Evaluation the data
Let’s start to evaluate our decision tree.
predictions = dtree.predict(x_test)
from sklearn.metrics import classification_report,confusion_matrix
print(classification_report(y_test,predictions))
precisionx recallx f1-scorex supportx
present 0.80 0.80 0.80 15
absent 0.45 0.45 0.45 10
avg / total 0.75 0.75 0.75 25
print(confusion_matrix(y_test,predictions))
[[18 4]
[ 2 3]
Tree Visualization
from IPython.display import Image
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
import pydot
features = list(df.columns[1:])
features
['Ages', 'Numbers', 'Starts']
dot_data = StringIO()
export_graphviz(dtree, out_file=dot_data,feature_names=features,filled=True,rounded=True)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
Image(graph[0].create_png())
![]() |
Decision Trees and Random Forests classifier-Types in Python |
Welcome everyone in python crash course (Machine learning). This is first part of this section,if you want to learn SVM in python then click on it.
K Nearest Neighbors method also used for data prediction purpose, so in his section we will learn K Nearest Neighbors predict method.
![]() |
k nearest neighbor python numpy language |
suppose you have been given a classified data set from a any popular company,they give you the data and the target classes and say predicts a class for a new data point based off of the features.
Let’s do it!
Get the Data
Set index_col=0
df.head()
Standardize the Variables K Nearest Neighbors method
In the next step we drop the TARGETC CLASSES from the data because this type of data affect on the prediction.
df_feat.head()
Train Test Split method:
Using KNN method
Remember we will start with k=1 value.
Predictions and Evaluations using knn
Let’s start to evaluate our KNN model!
print(confusions_matrix(y_test,pred))
print(classification_report(y_test,pred))
Choosing a correct value for K for this
we use the elbow method to pick a correct K Value:
![]() |
advantages and disadvantages in machine learning |
Logistic Regression in python 3.10 Hello friends, in the previous post we see the first part of Logistic Regression. for this post CLICK HERE. In this post we see Logistic…
Logistic Regression :Welcome everyone, this is first post of LOGISTIC REGRESSION. In the previous post we see Linear regression.If you are unknown about the Linear regression then CLICK HERE.OK Let's…
Linear Regression in Machine Learning: part02WELCOME TO SECOND PART OF YOUR LINEAR REGRESSION POST. IN THE FIRST POST WE SEE OPERATION ON DATASETS. IN THIS POST WE SEE LINEAR REGRESSION…