- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的 jupyter 笔记本:
import pandas as pd
from pprint import pprint
import pickle
import numpy as np
with open('preDF.p', 'rb') as f:
preDF = pickle.load(f)
#pprint(preDF)
df = pd.DataFrame(data=preDF)
#df.rename(columns={166: '166'}, inplace=True)
df.head()
0 1 2 3 4 5 6 7 8 9 ... 157 158 159 160 161 162 163 164 165 166
0 3 8 1 13 15 13 9 12 12 1 ... 0 0 0 0 0 0 0 0 0 1
1 3 1 13 15 13 9 12 12 1 27 ... 0 0 0 0 0 0 0 0 0 1
2 3 8 1 13 15 13 9 12 12 1 ... 0 0 0 0 0 0 0 0 0 1
3 13 5 20 18 9 3 1 18 9 1 ... 0 0 0 0 0 0 0 0 0 1
4 3 8 12 15 18 8 5 24 9 4 ... 0 0 0 0 0 0 0 0 0 2
5 rows × 167 columns
import numpy as np
#msk = np.random.rand(len(df)) < 0.8
#train = df[msk]
#test = df[~msk]
from sklearn.model_selection import KFold
kf = KFold(n_splits=2)
train = df.iloc[train_index]
test = df.iloc[test_index]
train.columns = train.columns.astype(np.int32)
test.columns = test.columns.astype(np.int32)
import tensorflow as tf
def train_input_fn(features, labels, batch_size):
"""An input function for training"""
# Convert the inputs to a Dataset.
dataset = tf.data.Dataset.from_tensor_slices((dict(features.astype(np.int32)), labels.astype(np.int32)))
# Shuffle, repeat, and batch the examples.
dataset = dataset.shuffle(1000).repeat().batch(batch_size)
# Return the dataset.
return dataset
def eval_input_fn(features, labels, batch_size):
"""An input function for evaluation or prediction"""
features=dict(features.astype(np.int32))
if labels is None:
# No labels, use only features.
inputs = features
else:
inputs = (features, labels)
# Convert the inputs to a Dataset.
dataset = tf.data.Dataset.from_tensor_slices(inputs)
# Batch the examples
assert batch_size is not None, "batch_size must not be None"
dataset = dataset.batch(batch_size)
# Return the dataset.
return dataset
def load_data(train,test,y_name=166):
train_x, train_y = train, train.pop(y_name)
test_x, test_y = test, test.pop(y_name)
return (train_x, train_y), (test_x, test_y)
def main(train,test):
batch_size = np.int32(100)
train_steps = np.int32(1000)
# Fetch the data
SPECIES = ['neg', 'stable', 'pos']
(train_x, train_y), (test_x, test_y) = load_data(train,test)
# Feature columns describe how to use the input.
my_feature_columns = []
for key in train_x.keys():
my_feature_columns.append(tf.feature_column.numeric_column(key=key))
# Build 2 hidden layer DNN with 10, 10 units respectively.
classifier = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
# Two hidden layers of 10 nodes each.
hidden_units=[30, 10,30],
# The model must choose between 3 classes.
n_classes=3)
classifier.train(
input_fn=lambda:train_input_fn(train_x, train_y,
batch_size),
steps=train_steps)
# Evaluate the model.
eval_result = classifier.evaluate(
input_fn=lambda:eval_input_fn(test_x, test_y,
batch_size))
print('\nTest set accuracy: {accuracy:0.3f}\n'.format(**eval_result))
# Generate predictions from the model
expected = ['exp neg', 'exp stable', 'exp pos']
predict_x = {
'open': [5.1, 5.9, 6.9],
'high': [3.3, 3.0, 3.1],
'low': [1.7, 4.2, 5.4],
'close': [0.5, 1.5, 2.1],
}
predictions = classifier.predict(
input_fn=lambda:eval_input_fn(predict_x,
labels=None,
batch_size=batch_size))
template = ('\nPrediction is "{}" ({:.1f}%), expected "{}"')
for pred_dict, expec in zip(predictions, expected):
class_id = pred_dict['class_ids'][0]
probability = pred_dict['probabilities'][class_id]
print(template.format(SPECIES[class_id],
100 * probability, expec))
if __name__ == '__main__':
#tf.logging.set_verbosity(tf.logging.INFO)
tf.app.run(main(train,test))
所以我得到这个错误:
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /tmp/tmpz7rw1puj
INFO:tensorflow:Using config: {'_task_type': 'worker', '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f478ba9bdd8>, '_tf_random_seed': None, '_keep_checkpoint_max': 5, '_is_chief': True, '_master': '', '_session_config': None, '_log_step_count_steps': 100, '_global_id_in_cluster': 0, '_evaluation_master': '', '_service': None, '_save_summary_steps': 100, '_save_checkpoints_secs': 600, '_num_ps_replicas': 0, '_task_id': 0, '_num_worker_replicas': 1, '_model_dir': '/tmp/tmpz7rw1puj', '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000}
INFO:tensorflow:Calling model_fn.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-141-fcd417d2c3ff> in <module>()
98 if __name__ == '__main__':
99 #tf.logging.set_verbosity(tf.logging.INFO)
--> 100 tf.app.run(main(train,test))
<ipython-input-141-fcd417d2c3ff> in main(train, test)
64 input_fn=lambda:train_input_fn(train_x, train_y,
65 batch_size),
---> 66 steps=train_steps)
67 # Evaluate the model.
68 eval_result = classifier.evaluate(
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in train(self, input_fn, hooks, steps, max_steps, saving_listeners)
350
351 saving_listeners = _check_listeners_type(saving_listeners)
--> 352 loss = self._train_model(input_fn, hooks, saving_listeners)
353 logging.info('Loss for final step: %s.', loss)
354 return self
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in _train_model(self, input_fn, hooks, saving_listeners)
810 worker_hooks.extend(input_hooks)
811 estimator_spec = self._call_model_fn(
--> 812 features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
813
814 if self._warm_start_settings:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py in _call_model_fn(self, features, labels, mode, config)
791
792 logging.info('Calling model_fn.')
--> 793 model_fn_results = self._model_fn(features=features, **kwargs)
794 logging.info('Done calling model_fn.')
795
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/canned/dnn.py in _model_fn(features, labels, mode, config)
352 dropout=dropout,
353 input_layer_partitioner=input_layer_partitioner,
--> 354 config=config)
355
356 super(DNNClassifier, self).__init__(
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/canned/dnn.py in _dnn_model_fn(features, labels, mode, head, hidden_units, feature_columns, optimizer, activation_fn, dropout, input_layer_partitioner, config)
183 dropout=dropout,
184 input_layer_partitioner=input_layer_partitioner)
--> 185 logits = logit_fn(features=features, mode=mode)
186
187 def _train_op_fn(loss):
/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/canned/dnn.py in dnn_logit_fn(features, mode)
89 partitioner=input_layer_partitioner):
90 net = feature_column_lib.input_layer(
---> 91 features=features, feature_columns=feature_columns)
92 for layer_id, num_hidden_units in enumerate(hidden_units):
93 with variable_scope.variable_scope(
/usr/local/lib/python3.5/dist-packages/tensorflow/python/feature_column/feature_column.py in input_layer(features, feature_columns, weight_collections, trainable, cols_to_vars)
271 """
272 return _internal_input_layer(features, feature_columns, weight_collections,
--> 273 trainable, cols_to_vars)
274
275
/usr/local/lib/python3.5/dist-packages/tensorflow/python/feature_column/feature_column.py in _internal_input_layer(features, feature_columns, weight_collections, trainable, cols_to_vars, scope)
192 ordered_columns.append(column)
193 with variable_scope.variable_scope(
--> 194 None, default_name=column._var_scope_name): # pylint: disable=protected-access
195 tensor = column._get_dense_tensor( # pylint: disable=protected-access
196 builder,
/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py in __enter__(self)
1901
1902 try:
-> 1903 return self._enter_scope_uncached()
1904 except:
1905 if self._graph_context_manager is not None:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py in _enter_scope_uncached(self)
2006 raise
2007 self._current_name_scope = current_name_scope
-> 2008 unique_default_name = _get_unique_variable_scope(self._default_name)
2009 pure_variable_scope = _pure_variable_scope(
2010 unique_default_name,
/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variable_scope.py in _get_unique_variable_scope(prefix)
1690 var_store = _get_default_variable_store()
1691 current_scope = get_variable_scope()
-> 1692 name = current_scope.name + "/" + prefix if current_scope.name else prefix
1693 if var_store.variable_scope_count(name) == 0:
1694 return prefix
TypeError: Can't convert 'numpy.int64' object to str implicitly
我的猜测是,这在不调用 numpy 作为简单示例的情况下也有效。
现在我已经调用了 numpy,每个 int 都是 int64,并且 tensorflow 似乎尝试非常简单地将 int 转换为字符串。
但是将 int64 转换为字符串并不是那么简单,所以失败了,因为现在所有 int 默认都是 int64。
但是我在查找这里哪个 int 有问题时遇到了一些问题。
笔记本在这里: https://www.dropbox.com/s/rx8v5aap3zhoshm/NewML.html?dl=1泡菜 predf 在这里: https://www.dropbox.com/s/wd831906jq3o1jl/preDF.p?dl=1
最佳答案
将列名称更新为字符串并尝试。
df.columns = df.columns.astype(str)
关于python - tensorflow 类型错误 : Can't convert 'numpy.int64' object to str implicitly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49632451/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!