本质上,我想创建一个数据库结构,允许以无限的方式对无限量的库存项目进行分类,但是,这些项目中的许多项目共享某些"特征".举个例子,Cars然后Trucks:
red或blue仅是.
2wd或4wd.
Cars可以拥有manual或automatic传播.Trucks可有cloth或leather座位我希望避免的是手动输入存在的每种可能的组合.有5种颜色和5种车辆,已经有25个条目,没有功能集分类.
是否存在允许这些关系和共享"特征组"的数据模型,或者更重要的是,是否允许单个引用我可以想象的任何数据集的每个可能组合?任何帮助将不胜感激.
让我尽可能具体.我的主要目标是跟踪我们为预算和历史目的而做的工作的材料使用情况.一些材料,即螺柱和轨道,将共享相同的子分类, 轨道具有第三子分类.有些人会有完全不同的分类.假设如下.
metal_widthsmetal_gaguestrack_typesinsulation_widthsinsulation_types......关系(可能的组合):
Studs> metal_widths> metal_gagues(25)Track> metal_widths> metal_gagues> track_types(100)Insulation> insulation_widths> insulation_types(15) …我正在使用Weka中的Naive Bayes分类器进行NLP分类项目.我打算使用半监督机器学习,因此使用未标记的数据.当我在一组独立的未标记测试数据上测试从我的标记训练数据中获得的模型时,Weka会忽略所有未标记的实例.任何人都可以指导我如何解决这个问题?之前有人已在此处提出此问题,但未提供任何适当的解决方案.这是一个示例测试文件:
@relation referents
@attribute feature1 NUMERIC
@attribute feature2 NUMERIC
@attribute feature3 NUMERIC
@attribute feature4 NUMERIC
@attribute class{1 -1}
@data
1, 7, 1, 0, ?
1, 5, 1, 0, ?
-1, 1, 1, 0, ?
1, 1, 1, 1, ?
-1, 1, 1, 1, ?
Run Code Online (Sandbox Code Playgroud) 为了学习支持向量机,我们必须确定各种参数。
例如,有成本和伽马等参数。
我正在尝试使用 R 的“GA”包和“kernlab”包来确定 SVM 的 sigma 和 gamma 参数。
我使用accuracy作为遗传算法的评价函数。
我创建了以下代码,并运行了它。
library(GA)
library(kernlab)
data(spam)
index <- sample(1:dim(spam)[1])
spamtrain <- spam[index[1:floor(dim(spam)[1]/2)], ]
spamtest <- spam[index[((ceiling(dim(spam)[1]/2)) + 1):dim(spam)[1]], ]
f <- function(x)
{
x1 <- x[1]
x2 <- x[2]
filter <- ksvm(type~.,data=spamtrain,kernel="rbfdot",kpar=list(sigma=x1),C=x2,cross=3)
mailtype <- predict(filter,spamtest[,-58])
t <- table(mailtype,spamtest[,58])
return(t[1,1]+t[2,2])/(t[1,1]+t[1,2]+t[2,1]+t[2,2])
}
GA <- ga(type = "real-valued", fitness = f, min = c(-5.12, -5.12), max = c(5.12, 5.12), popSize = 50, maxiter = 2)
summary(GA)
plot(GA)
Run Code Online (Sandbox Code Playgroud)
但是,当我调用 GA 函数时,返回以下错误。
“未找到支持向量。您可能需要更改参数”
我不明白为什么代码不好。
我想用R中的glmnet来做分类问题。
样本数据如下:
y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11
1,0.766126609,45,2,0.802982129,9120,13,0,6,0,2
0,0.957151019,40,0,0.121876201,2600,4,0,0,0,1
0,0.65818014,38,1,0.085113375,3042,2,1,0,0,0
Run Code Online (Sandbox Code Playgroud)
y 是二元响应(0 或 1)。
我使用了以下 R 代码:
prr=cv.glmnet(x,y,family="binomial",type.measure="auc")
yy=predict(prr,newx, s="lambda.min")
Run Code Online (Sandbox Code Playgroud)
然而,glmnet 预测的 yy 分散在 [-24,5] 之间。
如何将输出值限制为 [0,1] 从而我用它来解决分类问题?
我beieveSGDClassifier()与loss='log'支持多标记分类,我没有使用OneVsRestClassifier。检查这个
现在,我的数据集非常大,我正在使用HashingVectorizer并将结果作为输入传递给SGDClassifier. 我的目标有 42048 个特征。
当我运行它时,如下所示:
clf.partial_fit(X_train_batch, y)
Run Code Online (Sandbox Code Playgroud)
我得到:ValueError: bad input shape (300000, 42048)。
我也使用类作为参数如下,但仍然是同样的问题。
clf.partial_fit(X_train_batch, y, classes=np.arange(42048))
Run Code Online (Sandbox Code Playgroud)
在 SGDClassifier 的文档中,它说 y : numpy array of shape [n_samples]
classification machine-learning stochastic-process scikit-learn
我正在尝试使用hmeasure指标Hand,2009作为我在插入符号中训练SVM的自定义指标.由于我使用R相对较新,我尝试调整了twoClassSummary函数.我需要的是将真实的类标签和预测的类概率从模型(svm)传递到hmeasure包中的HMeasure函数,而不是使用ROC或插入符号中的其他分类性能度量.
例如,在R-HMeasure(true.class,predictProbs [,2])中调用HMeasure函数会导致计算Hmeasure.使用下面的twoClassSummary代码调整会导致返回错误:'x'必须是数字.
也许该列车功能不能"看到"预测的概率来评估HMeasure函数.我怎样才能解决这个问题?
我已经阅读了文档,并提出了关于SO 处理回归的问题.多数民众赞成让我走了一路.我将不胜感激任何帮助或指向解决方案.
library(caret)
library(doMC)
library(hmeasure)
library(mlbench)
set.seed(825)
data(Sonar)
table(Sonar$Class)
inTraining <- createDataPartition(Sonar$Class, p = 0.75, list = FALSE)
training <- Sonar[inTraining, ]
testing <- Sonar[-inTraining, ]
# using caret
fitControl <- trainControl(method = "repeatedcv",number = 2,repeats=2,summaryFunction=twoClassSummary,classProbs=TRUE)
svmFit1 <- train(Class ~ ., data = training,method = "svmRadial",trControl = fitControl,preProc = c("center", "scale"),tuneLength = 8,metric = "ROC")
predictedProbs <- predict(svmFit1, newdata = testing , type = "prob")
true.class<-testing$Class
hmeas<- HMeasure(true.class,predictedProbs[,2]) # suppose its …Run Code Online (Sandbox Code Playgroud) 文件说cutoff是"一个长度等于类数的向量.观察的'获胜'类是投票比例与截止比例的最大比例.默认为1/k,其中k是类的数量(即多数票获胜)."
我想实现0.6或0.7的概率截止值而不是0.5的默认值.
RFfit <- randomForest(Y ~ x1 + x2 + x3 + x4 + x5, data=mydata, mytry=2, ntrees=500,
cutoff = x)
Run Code Online (Sandbox Code Playgroud)
我试过x的各种值.0.6,6,12,1.2 ......似乎都没有用.我还在我的数据中添加了一个名为"cutoff"的列,其中所有值都是= 0.6,并尝试将其调用到代码中,但这也不起作用.
如何正确使用截止参数?
首先,手头的问题。我正在为一个scikit-learn类编写一个包装器,并且在使用正确的语法时遇到了问题。我想要实现的是fit_transform函数的覆盖,它只稍微改变输入,然后super用新参数调用它的-method:
from sklearn.feature_extraction.text import TfidfVectorizer
class TidfVectorizerWrapper(TfidfVectorizer):
def __init__(self):
TfidfVectorizer.__init__(self) # is this even necessary?
def fit_transform(self, x, y=None, **fit_params):
x = [content.split('\t')[0] for content in x] # filtering the input
return TfidfVectorizer.fit_transform(self, x, y, fit_params)
# this is the critical part, my IDE tells me for
# fit_params: 'unexpected arguments'
Run Code Online (Sandbox Code Playgroud)
程序到处崩溃,从 开始Multiprocessing exception,并没有真正告诉我任何有用的信息。我该如何正确地做到这一点?
附加信息:我需要以这种方式包装它的原因是因为我sklearn.pipeline.FeatureUnion在将它们放入sklearn.pipeline.Pipeline. 这样做的结果是,我只能在所有特征提取器中提供单个数据集——但不同的提取器需要不同的数据。我的解决方案是以易于分离的格式提供数据,并在不同的提取器中过滤不同的部分。如果这个问题有更好的解决方案,我也很高兴听到。
编辑 1:添加**解压 dict 似乎没有改变任何东西:

编辑 2:我刚刚解决了剩下的问题——我需要删除构造函数重载。显然,通过尝试调用父构造函数,希望正确启动所有实例变量,我做了完全相反的事情。我的包装器不知道它可以期待什么样的参数。一旦我删除了多余的电话,一切都很顺利。
我实施了一个作者归属项目,我能够使用 KNN 用两位作者的文章训练我的 KNN 模型。然后,我将一篇新文章的作者分类为作者 A 或作者 B。我使用 knn() 函数生成模型。模型的输出如下表。
Word1 Word2 Word3 Author
11 1 48 8 A
2 2 0 0 B
29 1 45 9 A
1 2 0 0 B
4 0 0 0 B
28 3 1 1 B
Run Code Online (Sandbox Code Playgroud)
从模型中可以明显看出,Word2 和 Word3 是导致 Author A 和 Author B 分类的最显着变量。
我的问题是如何使用 R 识别这一点。
以下代码用于生成随机森林的二进制分类的概率输出.
library(randomForest)
rf <- randomForest(train, train_label,importance=TRUE,proximity=TRUE)
prediction<-predict(rf, test, type="prob")
Run Code Online (Sandbox Code Playgroud)
然后关于预测的结果如下:
关于测试数据的真实标签是已知的(名为test_label).现在我想计算二进制分类概率输出的对数损失.关于LogLoss的功能如下.
LogLoss=function(actual, predicted)
{
result=-1/length(actual)*(sum((actual*log(predicted)+(1-actual)*log(1-predicted))))
return(result)
}
Run Code Online (Sandbox Code Playgroud)
如何用二进制分类的概率输出计算对数损失.谢谢.
classification ×10
r ×6
scikit-learn ×2
algorithm ×1
arff ×1
glmnet ×1
nlp ×1
python ×1
r-caret ×1
statistics ×1
svm ×1
weka ×1