ML Lab Program 7
ML Lab Program 7
Menu
Aim:
Source Code:
Week7.py
=================================
Explanation:
=================================
===> To run this program you need to install the pandas Module
===> To install, Open Command propmt and then execute the following comman
d
===> Open Command propmt and then execute the following command to install
sklearn Module
===============================
Source Code :
===============================
'''
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import accuracy_score, confusion_matrix, precision_sc
ore, recall_score
count_vect = CountVectorizer()
Xtrain_dims = count_vect.fit_transform(Xtrain)
Xtest_dims = count_vect.transform(Xtest)
df = pd.DataFrame(Xtrain_dims.toarray(),columns=count_vect.get_feature_nam
es_out())
clf = MultinomialNB()
# to fit the train data into model
clf.fit(Xtrain_dims, Ytrain)
# to predict the test data
prediction = clf.predict(Xtest_dims)
print('******** Accuracy Metrics *********')
print('Accuracy : ', accuracy_score(Ytest, prediction))
print('Recall : ', recall_score(Ytest, prediction))
print('Precision : ',precision_score(Ytest, prediction))
print('Confusion Matrix : \n', confusion_matrix(Ytest, prediction))
print(10*"-")
# to predict the input statement
test_stmt = [input("Enter any statement to predict :")]
test_dims = count_vect.transform(test_stmt)
pred = clf.predict(test_dims)
for stmt,lbl in zip(test_stmt,pred):
if lbl == 1:
print("Statement is Positive")
else:
print("Statement is Negative")
Statements_data.csv
Output:
Related Content :
4) Given the following data, which specify classifications for nine ombinations of VAR1 and VAR2 predict a
classification for a case where VAR1=0.906 and VAR2=0.606, using the result of k-means clustering with 3
means (i.e., 3 centroids) View Solution
5) The following training examples map descriptions of individuals onto high, medium and low credit-
worthiness.Input attributes are (from left to right) income, recreation, job, status, age-group, home-owner.
Find the unconditional probability of 'golf' and the conditional probability of 'single' given 'medRisk' in the
dataset View Solution
7) Implement naive baye's theorem to classify the English text View Solution
9) Implement the finite words classification system using Back-propagation algorithm View Solution
Suggestion/Feedback Form :
Name:
Full Name
Please provide rate this topic
This is a Compliment
This is Feedback
This is Grievance
Type Here..
Submit
ABOUT
Study Glance provides Tutorials , Power point Presentations(ppts), Lecture Notes,
Important & previously asked questions, Objective Type questions, Laboratory programs
and we provide Syllabus of various subjects.
CA TEGO R I ES
Tutorials Questions
PPTs Lab Programs
Lecture Notes Syllabus