我的数据框包含以下数据
product,values
a1, 10
a5, 20
a10, 15
a2, 45
a3, 12
a6, 67
Run Code Online (Sandbox Code Playgroud)
我必须根据产品列对数据框进行排序.我需要输出如下:
product,values
a10, 15
a6, 67
a5, 20
a3, 12
a2, 45
a1, 10
Run Code Online (Sandbox Code Playgroud)
我正面临以下错误:
ErrorDuringImport(path,sys.exc_info())
ErrorDuringImport:视图中的问题 -
我正在尝试在Windows 10系统上使用Anaconda环境来安装tensorflow 1.9.0。不幸的是,我位于防火墙后面,该防火墙阻止了对亚马逊云的所有访问(请不要问为什么)。
我知道我可以从这里安装 1.9.0 版本,但这个存储库严重依赖 conda-forge。
因此,为了规避这个问题,我使用以下命令(至少)安装tensorflow 1.8.0:
conda install -c https://repo.continuum.io/pkgs/main/win-64/ tensorflow-gpu=1.8.0
Run Code Online (Sandbox Code Playgroud)
这会产生以下输出:
解决环境:完成
套餐计划
环境位置:d:\Programs\Anaconda\Anaconda
添加/更新了规格:-tensorflow-gpu=1.8.0
将下载以下软件包:
Run Code Online (Sandbox Code Playgroud)package | build ---------------------------|----------------- bleach-1.5.0 | py36_0 24 KB conda-forge html5lib-0.9999999 | py36_0 182 KB conda-forge ------------------------------------------------------------ Total: 206 KB将安装以下新软件包:
Run Code Online (Sandbox Code Playgroud)absl-py: 0.2.2-py36_0 defaults astor: 0.6.2-py36_1 defaults gast: 0.2.0-py36_0 defaults grpcio: 1.12.1-py36h1a1b453_0 defaults markdown: 2.6.11-py36_0 defaults tensorboard: 1.8.0-py36he025d50_0 defaults tensorflow-base: 1.8.0-py36h1a1b453_0 defaults tensorflow-gpu-base: 1.8.0-py36h376609f_0 defaults termcolor: 1.1.0-py36_1 defaults以下软件包将被更新:
Run Code Online (Sandbox Code Playgroud)cudatoolkit: 8.0-4 defaults --> 9.0-1 defaults cudnn: 6.0-0 defaults …
我正在尝试使用 Keras(2.2.0 版)和 TensorFlow(1.1.0 版)训练 LSTM 神经网络。我知道有更新的 TensorFlow 版本,但不幸的是我在安装它们时遇到了一些问题。但是,我不认为我的问题与 TensorFlow 版本有关。
这是我的 Keras 代码的样子:
[...] from keras.layers import Dense, Dropout, LeakyReLU, LSTM, Activation, Dense, Dropout, Input, Embedding
def LSTM(X,Y):
inputDimension = len(X[0])
inputSize = len(X)
# create the model
model = Sequential()
model.add(Embedding(input_length=inputDimension,input_dim=inputDimension,output_dim=256))
model.add(LSTM(100))
model.add(Dropout(0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X,Y,epochs=3,batch_size=64)
return model
Run Code Online (Sandbox Code Playgroud)
每当我尝试运行它时,我都会收到以下错误消息:
回溯(最近一次调用最后一次):
文件“Main.py”,第 208 行,在 lstmModel = ann.LSTM(scaledTrainingX,trainingY)
文件“ann.py”,第 158 行,在 LSTM 模型中.add(LSTM(100))
TypeError: LSTM() missing 1 required位置参数:'Y'
我在 StackOverflow 上发现了这个问题,但建议的解决方案没有帮助,因为我没有使用生成器来训练我的网络。
任何帮助该网络运行的帮助将不胜感激。非常感谢。
我目前正在训练一个 Keras 模型,其相应的拟合调用如下所示:
model.fit(X,y_train,batch_size=myBatchSize,epochs=myAmountOfEpochs,validation_split=0.1,callbacks=myCallbackList)
Run Code Online (Sandbox Code Playgroud)
Keras Github 页面上的这条评论解释了“validation_split=0.1”的含义:
验证数据不一定取自每个类,它只是数据的最后 10%(假设您要求 10%)。
我现在的问题是:是否有一种简单的方法可以随机选择(例如)训练数据的 10% 作为验证数据?我想使用随机选取的样本的原因是,最后 10% 的数据不一定包含我的案例中的所有类。
非常感谢。
我正在尝试在 Python 中绘制一些SHAP 图,以更深入地了解我的机器学习模型的输出。这是我在 for 循环中调用的方法:
def plotAndSaveSHAPSummary(model,train_data,x_train,pathToSHAPPlots):
shap_values = model.get_feature_importance(train_data, type='ShapValues')
expected_value = shap_values[0,-1]
shap_values = shap_values[:,:-1]
shap.summary_plot(shap_values,x_train,max_display=20,show=False)
plt.savefig(pathToSHAPPlots+'/SHAP Plots/SHAP_Plot'+str(counter)+'.png',dpi=300,bbox_inches='tight')
plt.clf()
Run Code Online (Sandbox Code Playgroud)
绘图按预期保存到磁盘,但在每次调用 savefig 方法后,我收到以下错误消息:
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\PathTo\Anaconda\Lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:\PathTo\Anaconda\Lib\tkinter\__init__.py", line 749, in callit
func(*args)
File "D:\PathTo\Anaconda\lib\site-packages\matplotlib\backends\_backend_tk.py", line 270, in idle_draw
self.draw()
File "D:\PathTo\Anaconda\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "D:\PathTo\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 393, in draw
self.figure.draw(self.renderer)
File "D:\PathTo\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 1535, in _draw
def …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用卷积残差网络神经网络架构(ResNet)。到目前为止,我已经使用 Keras 实现了用于时间序列数据分类的简单卷积 (conv1D)。
现在,我正在尝试使用 Keras 构建 ResNet,但在尝试将其适应时间序列数据时遇到了一些困难。Keras 中 ResNet 或 Nasnet 的大多数实现(例如this one或that one)都使用 conv2D 来实现(这对图像有意义)。
有人可以帮助我为时间序列数据实现这个吗?
当谈到 Keras 的平均池化层时,我有点困惑。文档说明如下:
AveragePooling1D:时态数据的平均池化。
参数
Run Code Online (Sandbox Code Playgroud)pool_size: Integer, size of the average pooling windows. strides: Integer, or None. Factor by which to downscale. E.g. 2 will halve the input. If None, it will default to pool_size. padding: One of "valid" or "same" (case-insensitive). data_format: A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.channel_last 对应于具有形状(批次、步骤、特征)的输入,而 channels_first 对应于具有形状(批次、特征、步骤)的输入。
输入形状
Run Code Online (Sandbox Code Playgroud)If data_format='channels_last': 3D tensor with shape: (batch_size, steps, features) If data_format='channels_first': 3D tensor with …
我添加了一个文件env.conf,内容如下
MONO_GC_PARAMS=bridge-implementation=tarjan
MONO_GC_PARAMS=nursery-size=128m
MONO_GC_PARAMS=soft-heap-limit=512m
Run Code Online (Sandbox Code Playgroud)
到我的Android项目并将其构建操作配置为AndroidEnvironment。不幸的是,应用程序的输出表明旧的桥实现用于垃圾回收:
07-09 09:43:34.042 D / Mono(32084):GC_OLD_BRIDGE num-objects 228 num_hash_entries 20scsc大小1277 init 0.00ms df1 7.35ms排序2.87ms dfs2 2.96ms setup-cb 0.40ms免费数据3.11ms链接2593 / 2593/1284/16 DFS通过4870/3870
07-09 09:43:34.042 D /单声道(32084):GC_MAJOR:(LOS溢出)暂停60.33ms,总计61.31ms,桥接45.65ms主6864K / 6608K los 510K / 12016K
我正在使用Xamarin 3.11.666.0和Xamarin.Android 5.1.4.16,它似乎是这些软件包的最新版本。
如何为应用程序应用新的网桥实现?
Merge 未在 Keras/Tensorflow/Python3 版本上运行。在以前的版本中,合并正在运行。但现在,它没有运行。所以我想我应该用替换“合并”来转换此代码。新的 Keras/Tensorflow/Python3 版本中缺少“合并”。
如何重写 Merge(..., mode='ave') 和 Merge(...,mode='concat') ?
我的代码部分如下:
...
from keras.layers import Merge
...
left_branch = Sequential()
left_branch.add(Convolution3D...
...
right_branch = Sequential()
right_branch.add(Convolution3D...
...
merged = Merge([left_branch, right_branch], mode='ave')
lstm_branch = Sequential()
lstm_branch.add(Embedding(input_dim=7, output_dim=8, input_length=7))
lstm_branch.add(LSTM(output_dim=8, input_shape=(7, ) ))
lstm_branch.add(Dense(32, activation='relu'))
model = Sequential()
model.add(merged)
merged_2 = Merge([model, lstm_branch], mode='concat')
model_2 = Sequential()
model_2.add(merged_2)
model_2.add(Dense(nb_classes,init='normal'))
model_2.add(Activation('softmax'))
model_2.compile(loss='categorical_crossentropy', optimizer='RMSprop', metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud) 我有一个不平衡的数据集,有 53987 行、32 列和 8 个类。我正在尝试执行多类分类。这是我的代码和相应的输出:
from sklearn.metrics import classification_report, accuracy_score
import xgboost
xgb_model = xgboost.XGBClassifier(num_class=7, learning_rate=0.1, num_iterations=1000, max_depth=10, feature_fraction=0.7,
scale_pos_weight=1.5, boosting='gbdt', metric='multiclass')
hr_pred = xgb_model.fit(x_train, y_train).predict(x_test)
print(classification_report(y_test, hr_pred))
[10:03:13] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:541:
Parameters: { boosting, feature_fraction, metric, num_iterations, scale_pos_weight } might not be used.
This may not be accurate due to some parameters are only used in language bindings but
passed down to XGBoost core. Or some parameters are not used but slip through this verification. Please open an issue …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Windows 10 上运行XGBoost。我的代码的相关部分如下所示:
model = XGBClassifier()
print(x_train.shape)
print(y_train.shape)
print(np.isnan(x_train).any())
print(np.isnan(y_train).any())
print(np.isinf(x_train).any())
print(np.isinf(y_train).any())
print(np.isfinite(x_train).all())
print(np.isfinite(y_train).all())
model.fit(x_train, y_train)
Run Code Online (Sandbox Code Playgroud)
并产生以下结果:
(4116, 37)
(4116,)
False
False
False
False
True
True
The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1]. …Run Code Online (Sandbox Code Playgroud)