我正在尝试使用Matplotlib制作两套箱形图.我想要用不同的颜色填充(以及点和胡须)的每组盒子图.因此,情节基本上会有两种颜色
我的代码在下面,如果你可以帮助制作这些彩色图表会很棒.d0并且d1是每个数据列表的列表.我想要用d0一种颜色的数据制作的箱形图集,以及用d1另一种颜色的数据制作的箱形图集.
plt.boxplot(d0, widths = 0.1)
plt.boxplot(d1, widths = 0.1)
Run Code Online (Sandbox Code Playgroud) 有关应用功能,请参阅此处
我的混淆更多来自这个示例,我在下面的代码片段中添加了一些打印输出更多的调试信息,
grd = GradientBoostingClassifier(n_estimators=n_estimator)
grd_enc = OneHotEncoder()
grd_lm = LogisticRegression()
grd.fit(X_train, y_train)
test_var = grd.apply(X_train)[:, :, 0]
print "test_var.shape", test_var.shape
print "test_var", test_var
grd_enc.fit(grd.apply(X_train)[:, :, 0])
grd_lm.fit(grd_enc.transform(grd.apply(X_train_lr)[:, :, 0]), y_train_lr)
Run Code Online (Sandbox Code Playgroud)
输出是像下面,和困惑是什么样的数字6.,3.并且10.是什么意思?以及它们与最终分类结果的关系如何?
test_var.shape (20000, 10)
test_var [[ 6. 6. 6. ..., 10. 10. 10.]
[ 10. 10. 10. ..., 3. 3. 3.]
[ 6. 6. 6. ..., 11. 10. 10.]
...,
[ 6. 6. 6. ..., 10. 10. 10.]
[ 6. …Run Code Online (Sandbox Code Playgroud) 我需要为我的数据创建一个生成器,以传递给我的RNN训练函数.我有一份患者样本列表,其中每个样本都是三维长度为n i的时间序列(烦人地变化),我想创建批量数据,其中批量中的每个样本只属于一个患者但是每批可包含多个患者样本.这样做可以最大限度地增加我可以训练的样本数量而不会产生任何后果,因为我的RNN不是有状态的.起初我有以下功能
def dataIterator(rawDataList, config):
batchSize, nSteps = config.batchSize, config.nSteps
for rawData in rawDataList:
dataLen, dataWidth = rawData.shape
batchLen = dataLen // batchSize
data = np.zeros([batchSize, batchLen, dataWidth], dtype=np.float32)
for i in xrange(batchSize):
data[i] = rawData[batchLen*i:batchLen*(i+1), :]
epochSize = (batchLen - 1) // nSteps
if epochSize == 0:
raise ValueError('epoch_size == 0')
for i in xrange(epochSize):
x = data[:, i*nSteps:(i+1)*nSteps, :]
y = data[:, i*nSteps+1:(i+1)*nSteps+1, :]
yield (x, y)
Run Code Online (Sandbox Code Playgroud)
然而,这会修剪每个患者样本以适合批量大小.所以我想要创造所有可能批次的东西,包括最后的小号.然而,我对发电机的不熟悉让我非常困惑.到目前为止,我已经解决了它将不得不使用modulo aritmetic,但确切地说我不确定,所以我只是到了这一步:
def dataIterator(data, batchSize=batchSize, nSteps=nSteps, nDimensions=3): …Run Code Online (Sandbox Code Playgroud) from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vectorizer = TfidfVectorizer(max_df=0.95, max_features=200000,
min_df=.5, stop_words='english',
use_idf=True,sublinear_tf=True,tokenizer = tokenize_and_stem_body,ngram_range=(1,3))
tfidf_matrix_body = tfidf_vectorizer.fit_transform(totalvocab_stemmed_body)
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我错误
ValueError: After pruning, no terms remain. Try a lower min_df or a higher max_df.
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我解决相同的问题,并且我已将所有值 80 更改为 100 但问题仍然相同吗?
我想在基于文本语料库的scikit-learn 中创建一个 CountVectorizer,然后稍后将更多文本添加到 CountVectorizer(添加到原始字典)。
如果我使用transform(),它会保留原始词汇,但不会添加新词。如果我使用fit_transform(),它只会从头开始重新生成词汇表。见下文:
In [2]: count_vect = CountVectorizer()
In [3]: count_vect.fit_transform(["This is a test"])
Out[3]:
<1x3 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
In [4]: count_vect.vocabulary_
Out[4]: {u'is': 0, u'test': 1, u'this': 2}
In [5]: count_vect.transform(["This not is a test"])
Out[5]:
<1x3 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
In [6]: count_vect.vocabulary_
Out[6]: {u'is': 0, u'test': …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Tensorflow中创建一个LSTM网络,我在术语/基础知识上迷失了方向.我有n个时间序列例子,因此X = x n,其中 x i = [[x 1 1 x 1 2,x 1 3 ],...,[x m 1 x m 2,x m 3 ]]其中x 我我是一个浮子.首先,我想训练一个给出序列开始的模型([x 1 1 x 1 2,x 1 3 ])我可以预测序列的其余部分.然后我希望包含一个分类器来预测每个x i所属的二进制类.
所以我的问题是我在开始时提供什么并拉出模型的结尾?到目前为止,我有一些看起来像下面的东西
class ETLSTM(object):
"""docstring for ETLSTM"""
def __init__(self, isTraining, config):
super(ETLSTM, self).__init__()
# This needs to be tidied
self.batchSize = batchSize = config.batchSize
self.numSteps = numSteps = config.numSteps
self.numInputs = numInputs = config.numInputs
self.numLayers = …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个页面的 PDF,我使用过它pdftk并imagemagick使用下面的脚本分割并转换为 png。问题是我的 PDF 的某些页面是黑白的,其他页面是彩色的,这意味着我的一些图像保存为单通道,其余的是三通道。这给我带来了问题,最好在这里解决。
有谁知道我如何强制我的黑白图像具有三个通道,最好使用convert?
#!/bin/bash
for i in {1..105}
do
pdftk FNAME-12A.pdf cat $i output FNAME-12A_$i.pdf
convert -density 128 FNAME-12A_$i.pdf -quality 100 -channel RGB FNAME-12A_$i.png
done
Run Code Online (Sandbox Code Playgroud) 我对建模技术有点新意,我试图比较SVR和线性回归.我使用f(x)= 5x + 10线性函数来生成训练和测试数据集.到目前为止,我编写了以下代码片段:
import csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
with open('test.csv', 'r') as f1:
train_dataframe = pd.read_csv(f1)
X_train = train_dataframe.iloc[:30,(0)]
y_train = train_dataframe.iloc[:30,(1)]
with open('test.csv','r') as f2:
test_dataframe = pd.read_csv(f2)
X_test = test_dataframe.iloc[30:,(0)]
y_test = test_dataframe.iloc[30:,(1)]
svr = svm.SVR(kernel="rbf", gamma=0.1)
log = LinearRegression()
svr.fit(X_train.reshape(-1,1),y_train)
log.fit(X_train.reshape(-1,1), y_train)
predSVR = svr.predict(X_test.reshape(-1,1))
predLog = log.predict(X_test.reshape(-1,1))
plt.plot(X_test, y_test, label='true data')
plt.plot(X_test, predSVR, 'co', label='SVR')
plt.plot(X_test, predLog, 'mo', label='LogReg')
plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
正如您在图片中看到的,线性回归工作正常,但SVM的预测准确性较差. …
我在下面使用了递归函数的概念,但是从我对概念的理解,代码的输出应该是0,但这里的输出是012345,我不确定它是如何工作的.
有人可以向我解释一下,因为我的大学教授不能这样做.
#include<stdio.h>
#include<conio.h>
int yo(int a)
{
if(a>0)
{
yo(a-1); //using recursion function
}
printf("%d",a); //printing value
}
void main()
{
yo(5);
getch();
}
Run Code Online (Sandbox Code Playgroud) python ×8
scikit-learn ×4
bash ×1
box ×1
c ×1
colors ×1
dtls ×1
imagemagick ×1
keras ×1
lstm ×1
matplotlib ×1
nlp ×1
plot ×1
png ×1
regression ×1
svm ×1
tensorflow ×1
tf-idf ×1