2

홍채 꽃 데이터 세트를위한 간단한 분류자를 작성하기 위해 Siraj Raval의 YouTube 비디오를 따르고 있습니다. 이 비디오는 2016 년 5 월에 공개되었으므로 업데이트 된 Tensorflow의 일부 영역이 있다고 확신합니다. "tf.train.get.global_step으로 전환하십시오. 나는 구식의 Tensorflow 라이브러리에서 일하고 있으며, feature_columns를 연구하여 새 것을 알아 내려고 노력했다. . 오류가 어떤 도움을 크게 감사합니다 계속하고 교육 Tensorflow 사용자가되기에 어떤 조언은 공개적으로 환영합니다 여기 Tensorflow 분류 예에서 tf.train.get.global_step 오류가 발생했습니다

내 코드

import tensorflow.contrib.learn as skflow 
from sklearn import datasets, metrics 

iris = datasets.load_iris() 

feature_columns = skflow.infer_real_valued_columns_from_input(iris.data) 

classifier = skflow.LinearClassifier(feature_columns=feature_columns, n_classes=3) 

classifier.fit(iris.data, iris.target) 


score = metrics.accuracy_score(iris.target, classifier.predict(iris.data)) 

print("Accuracy: %f" % score) 

입니다 그리고 여기에 오류이다.

WARNING:tensorflow:float64 is not supported by many models, consider casting to float32. 
WARNING:tensorflow:Using temporary folder as model directory: C:\Users\isaia\AppData\Local\Temp\tmp8be6vyhq 
WARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with x is deprecated and will be removed after 2016-12-01. 
Instructions for updating: 
Estimator is decoupled from Scikit Learn interface by moving into 
separate class SKCompat. Arguments x, y and batch_size are only 
available in the SKCompat class, Estimator will only accept input_fn. 
Example conversion: 
    est = Estimator(...) -> est = SKCompat(Estimator(...)) 
WARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with y is deprecated and will be removed after 2016-12-01. 
Instructions for updating: 
Estimator is decoupled from Scikit Learn interface by moving into 
separate class SKCompat. Arguments x, y and batch_size are only 
available in the SKCompat class, Estimator will only accept input_fn. 
Example conversion: 
    est = Estimator(...) -> est = SKCompat(Estimator(...)) 
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32. 
WARNING:tensorflow:From C:\Users\isaia\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\linear.py:173: get_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version. 
Instructions for updating: 
Please switch to tf.train.get_global_step 

감사 사전에 도움을 청합니다.

답변

0

이 추정기 is basically deprecated은 다음 릴리스에서 텐서 흐름 (tensorflow)에서 제거 할 수 있으며 그에 대한 경고가 몇 가지 있습니다. tf.estimator.LinearClassifier을 사용해야합니다. API는 약간 다르지만 아이디어는 여전히 동일합니다. 전체 코드는 다음과 같습니다.

import numpy as np 
import tensorflow as tf 
from sklearn import datasets, metrics 

iris = datasets.load_iris() 

# The classifier 
feature_columns = [tf.feature_column.numeric_column("x", shape=[4])] 
classifier = tf.estimator.LinearClassifier(feature_columns=feature_columns, 
              n_classes=3) 

# Training 
train_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": iris.data}, 
                y=iris.target, 
                num_epochs=50, 
                shuffle=True) 
classifier.train(train_input_fn) 

# Testing 
test_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": iris.data}, 
                num_epochs=1, 
                shuffle=False) 
predictions = classifier.predict(test_input_fn) 
predicted_classes = [p["classes"].astype(np.float)[0] for p in predictions] 

score = metrics.accuracy_score(iris.target, predicted_classes) 
print("Accuracy: %f" % score) 
0

코드에 분류 번호 분류 번호로 연습 단계 수를 지정해야합니다. 나는 당신의 코드를 편집하고 필요한 곳에 코멘트를 주었다.

import tensorflow.contrib.learn as skflow 
from sklearn import datasets, metrics 

iris = datasets.load_iris() 

feature_columns = skflow.infer_real_valued_columns_from_input(iris.data) 

classifier = skflow.LinearClassifier(feature_columns=feature_columns,n_classes=3) 
classifier.fit(iris.data, iris.target,steps=10) #Define the Number of traning steps here 
results = classifier.predict(x=iris.data, as_iterable=False) #Set as_iterable=False to get an 1-D array for metrics.accuracy_score 

score = metrics.accuracy_score(iris.target, results) 

print("Accuracy: %f" % score) 

또한, 클래스 예측 같은 1-D 어레이를 얻기 위해, 사용자는 classifier.predict 방법 as_iterable = 거짓를 설정할 필요가있다.

희망이 도움이됩니다.