python


Is there a way for me to view the classes of particular instances in binary classified dataset using scikit learn


Is there a way for me to view the classes of particular instances in a binary classified dataset(classes are 0 or 1) using the scikit learn library. I have a program that performs knn on a dataset and inserts the model built into a database. I want to view instances in the the data that are classified as 0 or 1. This is the link to the dataset I am using https://drive.google.com/open?id=0B9cQtdthFqv3YVNBNk1peVltZkk
from sklearn import neighbors,datasets,preprocessing
from sklearn.cross_validation import train_test_split
import urllib.request
from sklearn.metrics import accuracy_score
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import model_selection
from sklearn.metrics import precision_recall_fscore_support as score
from sklearn.externals import joblib
from sklearn.model_selection import cross_val_score
from pandas import read_csv
from sklearn.ensemble import ExtraTreesClassifier
import pandas as pd
import numpy as np
import sys
import pickle
import mysql.connector as mc
def doSupervised(username,fileid,filename):
try:
connection = mc.connect (host = "localhost",
user = "**",
passwd = "**",
db = "**")
except mc.Error as e:
print("Error %d: %s" % (e.args[0], e.args[1]))
sys.exit(1)
cursor = connection.cursor()
# load data
dataframe = pd.DataFrame.from_csv(filename)
X= np.array(dataframe)
y = np.array(dataframe['Class'])
# fit an Extra Trees model to the data
model = ExtraTreesClassifier()
model.fit_transform(X, y)
# display the relative importance of each attribute
#print(model.feature_importances_)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
clf = neighbors.KNeighborsClassifier(algorithm='auto')
#fit the data to the model
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
#print (y_pred)
algorithmType="Supervised"
accuracy =accuracy_score(y_test, y_pred )
print(accuracy)
#save classifier to a file
name="supervisedmodel.pkl"
data = joblib.dump(clf, name)
#name = 'supervisedmodel.sav'
#data = pickle.dump(clf, open(name, 'wb'))
sql_command = "INSERT INTO machinelearningmodel (username, fileID,
name,data,accuracy,algorithmType ) VALUES (%s, %s, %s, %s, %s, %s)",
(username, str(fileid), name, str(data), str(accuracy),algorithmType)
cursor.execute(*sql_command)
#print(sql_command)
cursor.close()
connection.commit()
connection.close()
if __name__ == "__main__":
doSupervised(sys.argv[1],sys.argv[2],sys.argv[3])


Related Links

Final output don't return correct result in my Python multiprocessing code
how to fix the “W293 blank line contains whitespace”
How to create LinkExtractor rule which based on href in Scrapy
Accessing an Enum in Python
list comprehension returns error while try / except doesn't
Coding a recursive function on Python 3.0
How do I use the result of a function in a string?
How to stop Celery creating duplicated users in this task?
I'm trying to run an if-then true-false statement. How, I continuously receive errors when attempting to do so
Creating vertical dictionary from text file
Unable to import module even after adding __init__.py
Bluehost-Premature end of headers in python script
numpy.array_split() odd behavior
Memory allocation for numpy.array with copy=False?
Draw contours of detected objects using python and opencv
simple web crawler i need to eliminate the duplicate URL that present in the array

Categories

HOME
arrays
json
laravel-5
converter
jsf
payment-gateway
command
survival-analysis
sbt-assembly
azureservicebus
apple-numbers
adsense
snap.svg
nodemailer
i2c
octopus-deploy
lotus-notes
xul
multiple-monitors
rapidjson
riak-ts
arm-template
ada
jcl
facebook4j
memsql
cronet
xilinx-ise
roundcube
clockwork
skygear
modelandview
bing-maps-api
forecasting
topic-modeling
infusionsoft
flex4.5
ssh.net
dojox.mobile
median
filepath
automator
lumen-5.3
livefyre
pinvoke
photon-controller
react-native-fbsdk
redux-router
festival
objloader
pspice
verbose
windows-azure-pack
coordinate-transformation
gradle-release-plugin
altbeacon
getrusage
enyo
hornetq
rad
p-np
uialertview
android-snackbar
wif
vine
manjaro
criteria-api
jazz
guzzle6
magento-1.12
client-side-validation
grunt-express
method-overriding
ember-addon
spdy
coin-flipping
neoload
wss
ifft
visualstatemanager
javascriptmvc
carddav
argb
android-contextmenu
transitive-closure-table
javascriptserializer
z-machine
userid
hobo
testunit
windows-live-id
adsl
ihttphandler
symbol-server





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm