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

environment variable in ubuntu
Cross-platform Python Executables
Extract subarray from collection of 2D coordinates?
tkinter populate treeview using threading pool
How to make a function determining the winner of Tic-Tac-Toe more concise
Django update model entry using form fails
ctypes using HRESULT(python)
How to export property values with django-import-export
Plotting Coordinate Lines Using Matplotlib
BASH - Summarising information present in 2 genotype data columns in one column (ped file) [closed]
Python 3: How to call function from another file and pass arguments to that function ?
Streaming mp3 files in Django through Nginx
Opening PE file with Bokken
Python exercise: last letter / first letter
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
Replacing values in array from netCDF

Categories

HOME
security
jar
amazon-swf
bing
jasmine
vs-team-services
agile
wxwidgets
d
travis-ci
checksum
ll
phonegap-cli
gspread
apiconnect
internet-explorer-11
google-plus
powershell-v3.0
spinnaker
squarespace
mod-pagespeed
ada
attask
zoho
sonarqube-msbuild-runner
multiplayer
source-maps
qsub
jflex
samsung-mobile
tampermonkey
google-api-dotnet-client
mangodb
xor
freebase
google-guava-cache
rider
mmdrawercontroller
vsts-package-management
freetts
alchemy.js
android-maps-v2
finite-element-analysis
catia
php-ews
rapidweaver
recycle-bin
persistent
rhel6
dwarf
quintus
selenium-firefoxdriver
mercury
iron.io
emgu
sqldatareader
windows-azure-pack
manifest.mf
pydio
cron-task
uiprogressview
qregexp
nssplitview
uwp-maps
emokit
post-processing
yoothemes
sevenzipsharp
webhdfs
inputaccessoryview
viewflipper
gmaps4rails
microblaze
ibmsbt
adcolony
iostream
log4cplus
system.web
code-testing
colt
indexing-service
map-force
opensocial
svcutil.exe
robospice
onselect
vertical-rhythm
javascriptmvc
sharpmap
symphony-cms
fraud-prevention
xml-libxml
dynamic-data
pys60
feof
deploying
unions
die
signals2
curljs
printing-web-page
junit3
zend-form-element
winverifytrust
pci-bus
kpi
castle-validators
gears
interface-design

Resources

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
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App