我正在使用TensorFlow教程,该教程使用"怪异"格式上传数据.我想使用NumPy或pandas格式的数据,以便我可以将它与scikit-learn结果进行比较.
我从Kaggle获得了数字识别数据:https://www.kaggle.com/c/digit-recognizer/data .
这里是TensorFlow教程的代码(工作正常):
# Stuff from tensorflow tutorial
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder("float", shape=[None, 784])
y_ = tf.placeholder("float", shape=[None, 10])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
cross_entropy = -tf.reduce_sum(y_ * tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
Run Code Online (Sandbox Code Playgroud)
在这里,我读取数据,去掉目标变量并将数据分成测试和训练数据集(这一切都正常):
# Read dataframe from training data
csvfile='train.csv'
from pandas import DataFrame, read_csv
df = read_csv(csvfile)
# Strip off the target data and make it a separate …
Run Code Online (Sandbox Code Playgroud) 我们如何使用朴素贝叶斯解释weka中的分类结果?
如何计算平均值,标准差,重量和和精度?
如何计算kappa统计量,平均绝对误差,均方根误差等?
混淆矩阵的解释是什么?
随机森林中的包装袋错误是什么?它是在随机森林中找到正确数量的树的最佳参数吗?
language-agnostic classification machine-learning random-forest
我正在尝试将深度学习应用于目标类(500k,31K)之间的高级不平衡的二进制分类问题.我想写一个自定义的损失函数,应该是这样的:最小化(100 - ((predict_smallerclass)/(total_smallerclass))*100)
欣赏有关如何构建此逻辑的任何指示.
使用train_test_split()时如何获取数据的原始索引?
我所拥有的是以下内容
from sklearn.cross_validation import train_test_split
import numpy as np
data = np.reshape(np.randn(20),(10,2)) # 10 training examples
labels = np.random.randint(2, size=10) # 10 labels
x1, x2, y1, y2 = train_test_split(data, labels, size=0.2)
Run Code Online (Sandbox Code Playgroud)
但这并没有给出原始数据的索引.一种解决方法是将索引添加到数据(例如data = [(i, d) for i, d in enumerate(data)]
),然后将其传递到内部train_test_split
,然后再次展开.有没有更清洁的解决方案?
关于如何保存训练有素的分类器,我有点困惑.就像在每次我想要使用它时重新训练分类器显然是非常糟糕和缓慢的,我如何保存它并在需要时再次加载它?代码如下,提前感谢您的帮助.我正在使用Python和NLTK朴素贝叶斯分类器.
classifier = nltk.NaiveBayesClassifier.train(training_set)
# look inside the classifier train method in the source code of the NLTK library
def train(labeled_featuresets, estimator=nltk.probability.ELEProbDist):
# Create the P(label) distribution
label_probdist = estimator(label_freqdist)
# Create the P(fval|label, fname) distribution
feature_probdist = {}
return NaiveBayesClassifier(label_probdist, feature_probdist)
Run Code Online (Sandbox Code Playgroud) 当试图用sigmoid激活函数得到交叉熵时,两者之间存在差异
loss1 = -tf.reduce_sum(p*tf.log(q), 1)
loss2 = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(labels=p, logits=logit_q),1)
但是当使用softmax激活功能时,它们是相同的.
以下是示例代码:
import tensorflow as tf
sess2 = tf.InteractiveSession()
p = tf.placeholder(tf.float32, shape=[None, 5])
logit_q = tf.placeholder(tf.float32, shape=[None, 5])
q = tf.nn.sigmoid(logit_q)
sess.run(tf.global_variables_initializer())
feed_dict = {p: [[0, 0, 0, 1, 0], [1,0,0,0,0]], logit_q: [[0.2, 0.2, 0.2, 0.2, 0.2], [0.3, 0.3, 0.2, 0.1, 0.1]]}
loss1 = -tf.reduce_sum(p*tf.log(q),1).eval(feed_dict)
loss2 = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(labels=p, logits=logit_q),1).eval(feed_dict)
print(p.eval(feed_dict), "\n", q.eval(feed_dict))
print("\n",loss1, "\n", loss2)
Run Code Online (Sandbox Code Playgroud) classification machine-learning tensorflow cross-entropy sigmoid
我正在使用Python中的scikit-learn开发一种分类算法来预测某些客户的性别.除此之外,我想使用朴素贝叶斯分类器,但我的问题是我有混合的分类数据(例如:"在线注册","接受电子邮件通知"等)和连续数据(例如:"年龄","长度")会员资格"等).我之前没有使用scikit,但我认为高斯朴素贝叶斯适用于连续数据,而伯努利朴素贝叶斯可用于分类数据.但是,由于我想在我的模型中同时拥有分类和连续数据,我真的不知道如何处理这个问题.任何想法将不胜感激!
python classification machine-learning data-mining scikit-learn
我是机器学习和scikit-learn的新手.
我的问题:
(请纠正任何类型的误解)
我有一个BIG JSON数据集,我检索它并将其存储在trainList
变量中.
我预先处理它以便能够使用它.
完成后,我开始分类:
码:
我目前的变量:
trainList #It is a list with all the data of my dataset in JSON form
labelList #It is a list with all the labels of my data
Run Code Online (Sandbox Code Playgroud)
方法的大部分内容:
#I transform the data from JSON form to a numerical one
X=vec.fit_transform(trainList)
#I scale the matrix (don't know why but without it, it makes an error)
X=preprocessing.scale(X.toarray())
#I generate a KFold in order to make cross validation
kf …
Run Code Online (Sandbox Code Playgroud) python classification machine-learning scikit-learn supervised-learning
我正在研究数据挖掘,更确切地说是决策树.
我想知道是否有多种算法来构建决策树(或只有一个?),哪个更好,基于诸如
performance complexity-theory classification machine-learning decision-tree
classification ×10
python ×5
scikit-learn ×3
tensorflow ×3
data-mining ×1
naivebayes ×1
nltk ×1
pandas ×1
performance ×1
scipy ×1
sigmoid ×1
weka ×1