我想知道如何在Jupyter上的python中使用线性分类器来预测新数据(数组)
我在Jupyter中的python上使用Tensorflow线性分类器模型。我训练了模型,但是现在,当我尝试使用新的数组进行预测时,事情就不起作用了。您能告诉我解决该问题需要做什么吗?我尝试了枚举,包括范围,列表,打印以及我能想到的所有内容。你能帮我吗?
import pandas as pd
file="C:\\Users\\user\\pima-indians-diabetes-database.zip"
diabetes=pd.read_csv(file)
diabetes.replace(0, diabetes.replace([0], [None]))
diabetes.head(5)
diabetes.columns
normalize = ['Pregnancies','Glucose','BloodPressure','SkinThickness','Insulin','BMI', 'DiabetesPedigreeFunction']
diabetes[normalize]=diabetes[normalize].apply(lambda x:(x-x.min())/(x.max())-x.min())
import tensorflow as tf
nump = tf.feature_column.numeric_column('Pregnancies')
glucval = tf.feature_column.numeric_column('Glucose')
bp = tf.feature_column.numeric_column('BloodPressure')
intsk = tf.feature_column.numeric_column('SkinThickness')
insulinval = tf.feature_column.numeric_column('Insulin')
bmival = tf.feature_column.numeric_column('BMI')
dbf = tf.feature_column.numeric_column('DiabetesPedigreeFunction')
ageval = tf.feature_column.numeric_column('Age')
assignedg = tf.feature_column.categorical_column_with_vocabulary_list('Group',['A','B','C','D'])
import matplotlib.pyplot as plt
%matplotlib inline
diabetes['Age'].hist(bins=20)
x_data = diabetes.drop('Outcome',axis=1)
labels = diabetes['Outcome']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x_data,labels,test_size=.037, random_state=89)
input_func=tf.estimator.inputs.pandas_input_fn(x=X_train,y=y_train
,batch_size=5
,num_epochs= 1250
,shuffle=True)
age_buckets = tf.feature_column.bucketized_column(ageval, boundaries=[20,30,40,50,60,70,80])
feat_cols = ([nump,glucval,bp,intsk,insulinval,bmival,dbf,age_buckets])
model=tf.estimator.LinearClassifier(feature_columns=feat_cols,n_classes=2)
model.train(input_fn=input_func,steps=1250)
xdata = ([5,80,80,35,200,40,1.5,60])
请澄清一下,“ xdata”是我要预测的新数据。我只希望程序输出零或一,仅此而已,但是我尝试做的每件事都不断出错。只要它很简单,我怎么做都没关系。我不知道该使用哪种方法,请帮忙。后来,我想用Flask将其变成一个网站,如果可以的话,您能告诉我吗?谢谢。