小编Mar*_*rio的帖子

绘制一个奇特的对角相关矩阵,其系数位于上三角形中

我有以下合成数据框,包括数字列分类列以及label列。我想绘制一个对角相关矩阵并在上部显示相关系数,如下所示:

预期输出

图像

尽管合成数据集/数据帧中的分类列df需要转换为数值,但到目前为止,我已经使用了这个使用数据集的seaborn示例'titanic',该数据集是合成的并且适合我的任务,但我添加了label列,如下所示:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="white")

# Generate a large random dataset with synthetic nature (categorical + numerical)
data = sns.load_dataset("titanic")
df = pd.DataFrame(data=data)

# Generate label column randomly '0' or '1'
df['label'] = np.random.randint(0,2, size=len(df))

# Compute the correlation matrix
corr = df.corr()

# Generate a mask for the …
Run Code Online (Sandbox Code Playgroud)

python r heatmap rpy2 seaborn

10
推荐指数
1
解决办法
2837
查看次数

强制sklearn交叉验证分数使用分层k折?

基于Sklearn 文档

  • 是否可以强制使用StratifiedKFold
  • 我如何知道哪个KFold已被使用?

python scikit-learn k-fold

9
推荐指数
1
解决办法
5075
查看次数

Tensorboard - 可视化LSTM的权重

我正在使用几个LSTM层来形成深度递归神经网络.我想在训练期间监控每个LSTM层的权重.但是,我无法找到如何将LSTM图层权重的摘要附加到TensorBoard.

有什么建议可以做到这一点?

代码如下:

cells = []

with tf.name_scope("cell_1"):
    cell1 = tf.contrib.rnn.LSTMCell(self.embd_size, state_is_tuple=True, initializer=self.initializer)
    cell1 = tf.contrib.rnn.DropoutWrapper(cell1,
                input_keep_prob=self.input_dropout,
                output_keep_prob=self.output_dropout,
                state_keep_prob=self.recurrent_dropout)
    cells.append(cell1)

with tf.name_scope("cell_2"):
    cell2 = tf.contrib.rnn.LSTMCell(self.n_hidden, state_is_tuple=True, initializer=self.initializer)
    cell2 = tf.contrib.rnn.DropoutWrapper(cell2,
                output_keep_prob=self.output_dropout,
                state_keep_prob=self.recurrent_dropout)
    cells.append(cell2)

with tf.name_scope("cell_3"):
    cell3 = tf.contrib.rnn.LSTMCell(self.embd_size, state_is_tuple=True, initializer=self.initializer)
    # cell has no input dropout since previous cell already has output dropout
    cell3 = tf.contrib.rnn.DropoutWrapper(cell3,
                output_keep_prob=self.output_dropout,
                state_keep_prob=self.recurrent_dropout)
    cells.append(cell3)

cell = tf.contrib.rnn.MultiRNNCell(
    cells, state_is_tuple=True)

output, self.final_state = tf.nn.dynamic_rnn(
    cell,
    inputs=self.inputs,
    initial_state=self.init_state)
Run Code Online (Sandbox Code Playgroud)

tensorflow tensorboard

8
推荐指数
1
解决办法
3416
查看次数

在使用Keras进行的深度学习中如何利用多处理和多线程的优势?

我假设像keras / tensorflow / ...这样的大多数框架会自动使用所有CPU内核,但实际上它们似乎并没有。我只是发现很少的资源可以导致我们在深度学习过程中使用CPU的全部容量。我找到了一篇有关

from multiprocessing import Pool 
import psutil
import ray 
Run Code Online (Sandbox Code Playgroud)

另一方面,基于在多个过程中使用keras模型的答案,没有上述库的踪迹。是否有更优雅的方式利用Keras 的多处理功能,因为它在实施中非常受欢迎。

  • 例如,如何通过简单的RNN实现进行修改,以在学习过程中实现至少50%的CPU容量?

  • 我应该使用第二模型作为多任务处理(如LSTM)吗?我的意思是我们可以使用更多的CPU来同时管理运行多个模型吗?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from keras.layers.normalization import BatchNormalization
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import LSTM,SimpleRNN
from keras.models import Sequential
from keras.optimizers import Adam, RMSprop

df = pd.read_csv("D:\Train.csv", header=None) …
Run Code Online (Sandbox Code Playgroud)

python multithreading multiprocessing deep-learning keras

7
推荐指数
1
解决办法
783
查看次数

如何在 GridSearchCV 中正确选择最佳模型 - sklearn 和 caret 都做错了

考虑 3 个数据集训练/验证/测试。GridSearchCV()默认情况下选择具有最高交叉验证分数的最佳模型。在预测需要准确的现实环境中,这是选择最佳模型的可怕方法。原因是它应该如何使用:

  • 模型的训练集以学习数据集

  • Val 设置用于验证模型在训练集中学到的内容并更新参数/超参数以最大化验证分数。

  • 测试集 - 在未见过的数据上测试您的数据。

  • 最后,在实时环境中使用模型并记录结果,看看结果是否足以做出决策。令人惊讶的是,许多数据科学家仅仅选择验证分数最高的模型,就冲动地在生产中使用他们训练过的模型。我发现gridsearch选择的模型严重过度拟合,并且在预测看不见的数据方面比默认参数做得更差。

我的做法:

  • 手动训练模型并查看每个模型的结果(以某种循环方式,但效率不高)。这是非常手动且耗时的,但我得到的结果比gridsearch好得多。我希望这是完全自动化的。

  • 为我想要选择的每个超参数绘制验证曲线,然后选择显示训练集和验证集之间差异最小的超参数,同时最大化两者(即训练= 98%,验证= 78%确实很糟糕,但训练= 72% ,val=70% 是可以接受的)。

正如我所说,我想要一种更好的(自动化)方法来选择最佳模型。

我正在寻找什么样的答案:

我想最大化训练集和验证集中的分数,同时最小化训练集和验证集之间的分数差异。考虑以下网格搜索算法的示例:有两种模型:

Model A: train score = 99%, val score = 89%
Model B: train score = 80%, val score = 79%
Run Code Online (Sandbox Code Playgroud)

B 型是一个更可靠的模型,我随时都会选择 B 型而不是 A 型。它不太适合,并且预测是一致的。我们知道会发生什么。然而,gridsearch将选择模型 A,因为 val 分数更高。我发现这是一个常见问题,并且在互联网上没有找到任何解决方案。人们往往过于关注在学校学到的东西,而没有真正考虑选择过度拟合模型的后果。我看到了关于如何使用包中的gridsearch并让他们为您选择模型的冗余帖子,但没有看到如何实际选择最佳模型。

到目前为止,我的方法非常手动。我想要一种自动化的方式来做到这一点。

我目前所做的是这样的:

gs = GridSearchCV(model, params, cv=3).fit(X_train, y_train) # X_train and y_train consists …
Run Code Online (Sandbox Code Playgroud)

python r scikit-learn r-caret gridsearchcv

6
推荐指数
1
解决办法
5993
查看次数

应用sklearn.Linear_model.LinearRegression时如何限制CPU使用率?

我需要限制以下命令的 CPU 使用率,因为它使用了 100% 的 CPU。

    from sklearn.linear_model import LinearRegression
    model = LinearRegression(fit_intercept = True, n_jobs = 1)
    model.fit(df_x0, df_y0)
    model.predict(df_x1)
Run Code Online (Sandbox Code Playgroud)

我已经设置了n_jobs == 1,并且没有使用多处理,但它仍然使所有内核和df_y0. ndim == 1,我了解到n_jobs如果这样的话就不会有效。

谁能告诉我为什么它使用 100% 的 CPU,以及如何在 python 中解决这个问题?

Python 3.7、Linux。

python cpu-usage scikit-learn

6
推荐指数
1
解决办法
4653
查看次数

deepreplay 包出现问题:ValueError:无法创建组(名称已存在)

最近我在使用deepreplay 包时遇到了一个问题,因为它的 Traceback 如下:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-43-c3b5d8180301> in <module>()
----> 1 model.fit(X, y, epochs=50, batch_size=16, callbacks=[replay])

2 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

/usr/local/lib/python3.7/dist-packages/deepreplay/callbacks.py in on_train_begin(self, logs)
     83         self.n_epochs = self.params['epochs']
     84 
---> 85         self.group = self.handler.create_group(self.group_name)
     86         self.group.attrs['samples'] = self.params['samples']
     87         self.group.attrs['batch_size'] = self.params['batch_size']

/usr/local/lib/python3.7/dist-packages/h5py/_hl/group.py in create_group(self, name, track_order)
     63 …
Run Code Online (Sandbox Code Playgroud)

python h5py keyerror valueerror google-colaboratory

6
推荐指数
0
解决办法
234
查看次数

firebase 角度配置错误

这是当我在写入时按回车键时出现的错误ng serve -o

node_modules/@angular/fire/compat/proxy.d.ts:7:49 - error TS2344: Type 'T[K]' does not satisfy the constraint '(...args: any) => any'.
  Type 'T[FunctionPropertyNames<T>]' is not assignable to type '(...args: any) => any'.
    Type 'T[T[keyof T] extends Function ? keyof T : never]' is not assignable to type '(...args: any) => any'.
      Type 'T[keyof T]' is not assignable to type '(...args: any) => any'.
        Type 'T[string] | T[number] | T[symbol]' is not assignable to type '(...args: any) => any'.
          Type 'T[string]' is …
Run Code Online (Sandbox Code Playgroud)

firebase

6
推荐指数
1
解决办法
1530
查看次数

使用加权类处理 GradientBoostingClassifier 中的不平衡数据?

我有一个非常不平衡的数据集,我需要在此基础上构建一个模型来解决分类问题。该数据集有大约 30000 个样本,其中大约 1000 个样本被标记为\xe2\x80\x941\xe2\x80\x94,其余为 0。我通过以下几行构建模型:

\n\n
X_train=training_set\ny_train=target_value\nmy_classifier=GradientBoostingClassifier(loss=\'deviance\',learning_rate=0.005)\nmy_model = my_classifier.fit(X_train, y_train)\n
Run Code Online (Sandbox Code Playgroud)\n\n

由于这是一个不平衡的数据,因此像上面的代码一样简单地构建模型是不正确的,所以我尝试使用类权重,如下所示:

\n\n
class_weights = compute_class_weight(\'balanced\',np.unique(y_train), y_train)\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在,我不知道如何使用 class_weights(基本上包括 0.5 和 9.10 值)来训练和构建模型GradientBoostingClassifier

\n\n

任何想法?我如何使用加权类或其他技术处理这些不平衡的数据?

\n

python machine-learning training-data scikit-learn boosting

5
推荐指数
1
解决办法
5063
查看次数

如何修复“此应用程序中的调试检查失败”错误?

我最近设法在一台新计算机上安装了 Code::Blocks 和 MinGW 编译器。

我在 Code::Blocks 上的调试器有问题。它实际上不会让我创建任何项目并给我一条错误消息。

错误消息如下:

wxWidgets Debug Alert

A debugging check in this application has failed.

../../src/common/file.cpp(361): assert ""(pBuf != __null) && IsOpened()"" failed in Write()
Run Code Online (Sandbox Code Playgroud)

这是整个事情的图片:[错误消息] 图片

如果我按停止,那么一切都会崩溃。

但是,如果我按继续,则会收到此警告:

Warning

Couldn't save project C:\Users\40737\Documents\yy\yy.cbp

(Maybe the file is write-protected?)
Run Code Online (Sandbox Code Playgroud)

这是一张图片:[警告信息] 图片

如果我继续点击确定,同样的错误会再次出现:

再来一张图:【错误再次出现】 图片

有什么可做的?

c++ debugging

5
推荐指数
2
解决办法
3万
查看次数