小编Nic*_*san的帖子

phpMyAdmin - "请输入有效长度"

我正在尝试在phpMyAdmin中创建一个表,无论我如何操作SQL代码,我都会遇到同样的错误.这是phpMyAdmin生成的预览SQL

CREATE TABLE `puppies`.`animals` ( 
    `id` INT(11) NOT NULL AUTO_INCREMENT , 
    `puppy_name` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
    `breed_id` INT(11) NOT NULL , 
    `description` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
    `price` DECIMAL(10,2) NOT NULL , 
    `picture_url` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
    `sold` TINYINT(1) NOT NULL , 
    PRIMARY KEY (`id`)
) ENGINE = InnoDB;
Run Code Online (Sandbox Code Playgroud)

我用括号和逗号的多种变体尝试了它.

mysql phpmyadmin

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

使用网格搜索的交叉验证返回比默认值更差的结果

我在Python中使用scikitlearn来运行一些基本的机器学习模型.使用内置的GridSearchCV()函数,我确定了不同技术的"最佳"参数,但其中许多都比默认值更差.我包含默认参数作为选项,所以我很惊讶这会发生.

例如:

from sklearn import svm, grid_search
from sklearn.ensemble import GradientBoostingClassifier
gbc = GradientBoostingClassifier(verbose=1)
parameters = {'learning_rate':[0.01, 0.05, 0.1, 0.5, 1],  
              'min_samples_split':[2,5,10,20], 
              'max_depth':[2,3,5,10]}
clf = grid_search.GridSearchCV(gbc, parameters)
t0 = time()
clf.fit(X_crossval, labels)
print "Gridsearch time:", round(time() - t0, 3), "s"
print clf.best_params_
# The output is: {'min_samples_split': 2, 'learning_rate': 0.01, 'max_depth': 2}
Run Code Online (Sandbox Code Playgroud)

这与默认值相同,但max_depth为3.当我使用这些参数时,我得到72%的准确度,而默认值为78%.

我做的一件事,我承认是可疑的,是我使用我的整个数据集进行交叉验证.然后在获得参数后,我使用相同的数据集运行它,分成75-25训练/测试.

我的网格搜索是否有理由忽视"优越"默认值?

python machine-learning scikit-learn cross-validation grid-search

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

SVM内核的速度?线性与RBF对比

我在Python中使用scikitlearn来创建一些SVM模型,同时尝试不同的内核.代码非常简单,遵循以下形式:

from sklearn import svm
clf = svm.SVC(kernel='rbf', C=1, gamma=0.1) 
clf = svm.SVC(kernel='linear', C=1, gamma=0.1) 
clf = svm.SVC(kernel='poly', C=1, gamma=0.1) 
t0 = time()
clf.fit(X_train, y_train)
print "Training time:", round(time() - t0, 3), "s"
pred = clf.predict(X_test)
Run Code Online (Sandbox Code Playgroud)

数据是8个特征和超过3000个观测值.我很惊讶地看到rbf在一秒钟内完成,而线性花费了90秒,而poly则需要数小时.

我认为非线性内核会更复杂并且需要更多时间.是否有一个原因是线性比rbf花费的时间长得多,并且poly比两者都要长得多?它可以根据我的数据发生巨大变化吗?

python svm scikit-learn

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

R - 仅微调选定的值并使用 geom_text_repel 保持其他值不变

我想使用 geom_text_repel 使我的标签尽可能靠近饼图的边缘,除非百分比低于某个值,在这种情况下,标签应该被推得更远并用一条线连接。我从ggplot2 饼图中的移动标签中调整了一个解决方案,但增加了高于阈值的组的 xpos 值。

library(dplyr)
library(ggplot2)
library(ggrepel)
library(scales)
threshold = 0.05    
age <- data.frame(Age = c("20 - 29", "30 - 39", "40 - 49", "50 - 59", "60 - 69"), count = c(27, 29, 26, 16, 2))
age <- age %>% mutate(percent = count/sum(count),
            cs = rev(cumsum(rev(percent))),
            ypos = percent/2 + lead(cs, 1),
            ypos = ifelse(is.na(ypos), percent/2, ypos),
            xpos = ifelse(percent > threshold, 1.8, 1.3),
            xn = ifelse(percent > threshold, 0, 0.5))
ggplot(age, aes_string(x = 1, …
Run Code Online (Sandbox Code Playgroud)

r graph geom-text

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

使用while <0条件将字符串输入scanf会导致无限循环

我有一个"分钟"变量,我希望用户输入一个正数.

int main(void)
{
    float minutes;
    minutes = -1;
    printf("Find out how many bottles worth of water your showers use!\n");
    printf("How many minutes do you spend in the shower? ");
    scanf("%f", &minutes);
    while(minutes < 0)
    {
        printf("Please enter a positive number: ");
        scanf("%f", &minutes);
    }
}
Run Code Online (Sandbox Code Playgroud)

它适用于数字.如果分钟> = 0,它接受它,如果分钟<0,它会一直询问.如果我输入一个字符串,它会无限循环

printf("Please enter a positive number: "); 
Run Code Online (Sandbox Code Playgroud)

从来没有给我机会输入新的价值.为什么这样,我该如何解决?谢谢!

c string while-loop

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

ggplot - x 轴显示超出指定范围的较长时间段的数据

以下是公司按两个群组划分的净收入的一些示例数据:

data <- data.frame(dates = rep(seq(as.Date("2000/1/1"), by = "month", length.out = 48), each = 2),
                   revenue = rep(seq(10000, by = 1000, length.out = 48), each = 2) * rnorm(96, mean = 1, sd = 0.1),
                   cohort = c("Group 1", "Group 2"))
Run Code Online (Sandbox Code Playgroud)

我可以显示一年的数据,它会返回我所期望的:

start = "2000-01-01"
end = "2000-12-01"

ggplot(data, aes(fill = cohort, x = dates, y = revenue)) +
    geom_bar(stat = "identity", position = position_dodge(width = NULL)) +
    xlab("Month") + 
    ylab("Net Revenue") +
    geom_text(aes(label = round(revenue, 0)), vjust = -0.5, …
Run Code Online (Sandbox Code Playgroud)

r graph ggplot2

4
推荐指数
1
解决办法
375
查看次数