小编Mon*_*lal的帖子

`对比<-`(`*tmp*`,value = contr.funs [1 + isOF [nn]])出错:对比只能应用于2级或更多级别的因子

我有以下代码用于使用optim()来查找beta0和beta1来最小化偏差之和但我收到以下错误我不知道我做错了什么:

sum.abs.dev<-function(beta=c(beta0,beta1),a,b)
{
  total<-0
  n<-length(b)
  for (i in 1:n)
  {
    total <- total + (b[i]-beta[1]-beta[2]*a[i])
  }
  return(total)
}
tlad <- function(y = "farm", x = "land", data="FarmLandArea.csv")
{

  dat <- read.csv(data)

  #fit<-lm(dat$farm~dat$land)
  fit<-lm(y~x,data=dat)
  beta.out=optim(fit$coefficients,sum.abs.dev)

  return(beta.out)
}
Run Code Online (Sandbox Code Playgroud)

这是错误和警告:

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels In addition: Warning message:
In model.response(mf, "numeric") : NAs introduced by coercion
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

csv optimization regression r function

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

检查模型输入时出错:预期卷积2d_input_1具有形状(无,3,32,32)但是具有形状的数组(50000,32,32,3)

有人可以指导如何解决此错误?我刚刚开始在Keras:

 1 from keras.datasets import cifar10
  2 from matplotlib import pyplot
  3 from scipy.misc import toimage
  4 
  5 (x_train, y_train), (x_test, y_test) = cifar10.load_data()
  6 for i in range(0, 9):
  7     pyplot.subplot(330 + 1 + i)
  8     pyplot.imshow(toimage(x_train[i]))
  9 pyplot.show()
 10 
 11 import numpy
 12 from keras.models import Sequential
 13 from keras.layers import Dense
 14 from keras.layers import Dropout
 15 from keras.layers import Flatten
 16 from keras.constraints import maxnorm
 17 from keras.optimizers import SGD
 18 from keras.layers.convolutional import Convolution2D
 19 …
Run Code Online (Sandbox Code Playgroud)

python deep-learning keras tensorflow

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

RuntimeError:只能计算浮点类型的平均值。取而代之的是字节。对于平均值 += images_data.mean(2).sum(0)

我有以下代码:

# Device configuration
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
seed = 42
np.random.seed(seed)
torch.manual_seed(seed)

# split the dataset into validation and test sets
len_valid_set = int(0.1*len(dataset))
len_train_set = len(dataset) - len_valid_set

print("The length of Train set is {}".format(len_train_set))
print("The length of Test set is {}".format(len_valid_set))

train_dataset , valid_dataset,  = torch.utils.data.random_split(dataset , [len_train_set, len_valid_set])

# shuffle and batch the datasets
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=8, shuffle=True, num_workers=4)
test_loader = torch.utils.data.DataLoader(valid_dataset, batch_size=8, shuffle=True, num_workers=4)

print("LOADERS",
    len(dataloader),
    len(train_loader),
    len(test_loader))
Run Code Online (Sandbox Code Playgroud)

火车组的长度是720

测试集的长度为80

装载机 …

python deep-learning pytorch dataloader

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

使用R函数查找文件中单词的出现次数

我使用以下代码来查找memory文件中单词的出现次数,我得到了错误的结果.你能帮助我知道我错过了什么吗?

注1:问题是寻找"记忆"一词的确切出现!注意2:我已经意识到他们正在寻找"记忆"甚至是"记忆"之类的东西是不被接受的!那是我猜想引起混乱的部分.我试了一下"动作"这个词,正确答案是7!你也可以试试.

#names=scan("hamlet.txt", what=character())
names <- scan('http://pastebin.com/raw.php?i=kC9aRvfB', what=character())
Read 28230 items
> length(grep("memory",names))
[1] 9
Run Code Online (Sandbox Code Playgroud)

这是文件

grep r file

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

如何在不使用Python外部库的情况下解析Arff文件

我需要在不使用任何外部库的情况下解析如下的arff文件。我不确定如何将属性与数值关联起来。就像我怎么说每一行的第一个数字是年龄,而第二行的是性别?您还可以将我链接到一些用于解析类似情况的python代码吗?

@relation cleveland-14-heart-disease
@attribute 'age' real
@attribute 'sex' { female, male}
@attribute 'cp' { typ_angina, asympt, non_anginal, atyp_angina}
@attribute 'trestbps' real
@attribute 'chol' real
@attribute 'fbs' { t, f}
@attribute 'restecg' { left_vent_hyper, normal, st_t_wave_abnormality}
@attribute 'thalach' real
@attribute 'exang' { no, yes}
@attribute 'oldpeak' real
@attribute 'slope' { up, flat, down}
@attribute 'ca' real
@attribute 'thal' { fixed_defect, normal, reversable_defect}
@attribute 'class' { negative, positive}
@data
63,male,typ_angina,145,233,t,left_vent_hyper,150,no,2.3,down,0,fixed_defect,negative
37,male,non_anginal,130,250,f,normal,187,no,3.5,down,0,normal,negative
41,female,atyp_angina,130,204,f,left_vent_hyper,172,no,1.4,up,0,normal,negative
56,male,atyp_angina,120,236,f,normal,178,no,0.8,up,0,normal,negative
57,female,asympt,120,354,f,normal,163,yes,0.6,up,0,normal,negative
57,male,asympt,140,192,f,normal,148,no,0.4,flat,0,fixed_defect,negative
56,female,atyp_angina,140,294,f,left_vent_hyper,153,no,1.3,flat,0,normal,negative
44,male,atyp_angina,120,263,f,normal,173,no,0,up,0,reversable_defect,negative
52,male,non_anginal,172,199,t,normal,162,no,0.5,up,0,reversable_defect,negative
Run Code Online (Sandbox Code Playgroud)

这是我编写的示例代码:

arr=[]
arff_file = …
Run Code Online (Sandbox Code Playgroud)

python parsing machine-learning arff

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

没有适用于'xpathApply'的适用方法应用于类“ NULL”的对象

我有以下代码,我不知道为什么会收到此错误:

rm(list=ls())
require("XML")
# <a href="/music/The+Beatles/Sgt.+Pepper%27s+Lonely+Hearts+Club+Band" 
beatles = "http://www.last.fm/music/The+Beatles/"

beatles.albums.page = paste(sep="", beatles, "+albums")
lines = readLines(beatles.albums.page)
album.lines = grep(pattern="href.*link-reference", lines, value=TRUE)
album.names = sub(pattern=".*<h3>(.*)</h3>.*", replacement="\\1", x=album.lines)
album.names = gsub(pattern=" ", replacement="+", x=album.names)
album.names = gsub(pattern="'", replacement="%27", x=album.names)

for (album in album.names[1]) {
  print(album)
  album.link = paste(sep="", beatles, album)
  print(album.link)
  tables = readHTMLTable(album.link)

}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

html regex r last.fm web-scraping

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

UnicodeEncodeError:'ascii'编解码器无法编码位置0-1中的字符:序数不在范围内(128)

我不确切知道这个错误的来源是什么以及如何修复它.我通过运行此代码得到它.

 Traceback (most recent call last):
      File "t1.py", line 86, in <module>
        write_results(results)
      File "t1.py", line 34, in write_results
        dw.writerows(results)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 154, in writerows
        return self.writer.writerows(rows)
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

任何解释都非常感谢!

我更改了代码,现在我收到此错误:

 File "t1.py", line 88, in <module>
    write_results(results)
  File "t1.py", line 35, in write_results
    dw.writerows(results)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 154, in writerows
    return self.writer.writerows(rows)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) …
Run Code Online (Sandbox Code Playgroud)

python unicode

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

向上舍入 bc 比例而不是使用比例或 printf 向下舍入

我使用 bc 和 scale 来评估表达式,但是我希望它向上舍入而不是向下舍入。什么是最简单的方法来做到这一点?

$ read exp
5+50*3/20 + (19*2)/7
$ echo "scale=3; $exp" | bc -l
17.928
Run Code Online (Sandbox Code Playgroud)

然而我想要的答案是 17.929

我更喜欢将答案作为我的答案的附录,而不是一些不同的东西。谢谢

以下是我尝试过的一些事情:

$ echo "scale=4; ($exp+0.0005)" | bc -l
17.9290
$ echo "scale=3; ($exp+0.0005)" | bc -l
17.9285
Run Code Online (Sandbox Code Playgroud)

但是我想17.929作为最后没有零的答案。

bash shell expression sh bc

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

PermissionError:[WinError 5]访问被拒绝:'C:\\ Program Files \\ Anaconda3 \\ pkgs \\ vs2015_runtime-14.0.25123-0.tmp

康达新手在这里!我怎么解决这个问题?

C:\Users\mona>conda create --name universe-starter-agent python=3.5
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment C:\Users\mona\.conda\envs\universe-starter-agent:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pip-9.0.1                  |           py35_1         1.7 MB

The following NEW packages will be INSTALLED:

    pip:            9.0.1-py35_1
    python:         3.5.2-0       (copy)
    setuptools:     27.2.0-py35_1 (copy)
    vs2015_runtime: 14.0.25123-0  (copy)
    wheel:          0.29.0-py35_0 (copy)

Proceed ([y]/n)? y

Fetching packages ...
pip-9.0.1-py35 100% |###############################| Time: 0:00:00   2.94 MB/s
Extracting packages ...
WARNING conda.lock:touch(53): Failed to create lock, do …
Run Code Online (Sandbox Code Playgroud)

python access-denied python-3.x conda windows-10

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

ModuleNotFoundError:没有名为“tensorflow.keras”的模块

我已经使用 github 页面上的指南安装了DeepPoseKit 。

我有以下tensorflow-gpu版本:

[jalal@goku examples]$ python -c 'import tensorflow as tf; print(tf.__version__)'
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow

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