我使用以下代码来查找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)
这是文件
我需要在不使用任何外部库的情况下解析如下的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) 我有以下代码,我不知道为什么会收到此错误:
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)
任何的想法?
康达新手在这里!我怎么解决这个问题?
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) 我想将我的pandas数据帧的'Time'列中的所有项目从UTC转换为Eastern时间.但是,根据此stackoverflow帖子中的答案,pandas 0.20.3中不知道某些关键字.总的来说,我该怎么做呢?
tweets_df = pd.read_csv('valid_tweets.csv')
tweets_df['Time'] = tweets_df.to_datetime(tweets_df['Time'])
tweets_df.set_index('Time', drop=False, inplace=True)
Run Code Online (Sandbox Code Playgroud)
错误是:
tweets_df['Time'] = tweets_df.to_datetime(tweets_df['Time'])
File "/scratch/sjn/anaconda/lib/python3.6/site-packages/pandas/core/generic.py", line 3081, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'to_datetime'
Run Code Online (Sandbox Code Playgroud)
时间列中的项目如下所示:
2016-10-20 03:43:11+00:00
Run Code Online (Sandbox Code Playgroud)
更新:使用
tweets_df['Time'] = pd.to_datetime(tweets_df['Time'])
tweets_df.set_index('Time', drop=False, inplace=True)
tweets_df.index = tweets_df.index.tz_localize('UTC').tz_convert('US/Eastern')
Run Code Online (Sandbox Code Playgroud)
没有时间转换.知道什么可以修复吗?
更新2:所以下面的代码,当我使用iterrows()打印行['Time']时,它不会进行就地转换,它显示原始值.你知道如何进行就地转换吗?
tweets_df['Time'] = pd.to_datetime(tweets_df['Time'])
for index, row in tweets_df.iterrows():
row['Time'].tz_localize('UTC').tz_convert('US/Eastern')
for index, row in tweets_df.iterrows():
print(row['Time'])
Run Code Online (Sandbox Code Playgroud) 我试图找到列中以及整个数据帧内的NAs百分比:
我评论的第一种方法给了我零,而没有评论的第二种方法给了我一个矩阵.不确定我错过了什么.真的很感激任何提示!
cp.2006<-read.csv(file="cp2006.csv",head=TRUE)
#countNAs <- function(x) {
# sum(is.na(x))
#}
#total=0
#for (i in col(cp.2006)) {
# total=countNAs(i)+total
#}
#print(total)
count<-apply(cp.2006, 1, function(x) sum(is.na(x)))
dims<-dim(cp.2006)
num<-dims[1]*dims[2]
NApercentage<-(count/num) * 100
print(NApercentage)
Run Code Online (Sandbox Code Playgroud) 我不知道如何消除这个错误。我正在使用“bitbucket”私下上传我的项目,但即使我已删除所有更改的文件,我仍收到以下错误。我只是想拉取文件
error: Your local changes to the following files would be overwritten by merge:
buf.cpp
buf.h
Please, commit your changes or stash them before you can merge.
Aborting
Run Code Online (Sandbox Code Playgroud)
这是我使用的命令:
git pull origin
Run Code Online (Sandbox Code Playgroud) 我该如何解决这个错误?我需要使用 Anaconda Python 3.6。
dhcp-wifi-8021x-155-41-106-41:~ Tkixi$ conda update jupyter numpy mysql-connector-python scipy
PackageNotInstalledError: Package is not installed in prefix.
prefix: /Users/Tkixi/anaconda
package name: mysql-connector-python
dhcp-wifi-8021x-155-41-106-41:~ Tkixi$ conda list
# packages in environment at /Users/Tkixi/anaconda:
#
_license 1.1 py36_1
alabaster 0.7.10 py36_0
anaconda custom py36_0
anaconda-client 1.6.3 py36_0
anaconda-navigator 1.6.2 py36_0
anaconda-project 0.6.0 py36_0
appnope 0.1.0 py36_0
appscript 1.0.1 py36_0
asn1crypto 0.22.0 py36_0
astroid 1.4.9 py36_0
astropy 1.3.2 np112py36_0
babel 2.4.0 py36_0
backports 1.0 py36_0
beautifulsoup4 4.6.0 py36_0
bitarray 0.8.1 py36_0 …Run Code Online (Sandbox Code Playgroud) 您能指导如何解决此问题吗?
with tf.name_scope('loss'):
#cross_entropy = None
val = tf.nn.softmax_cross_entropy_with_logits(y_conv, y_)
cross_entropy = tf.reduce_mean(val)
with tf.name_scope('adam_optimizer'):
#train_step = None
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-f67d0aecc114> in <module>()
1 with tf.name_scope('loss'):
2 #cross_entropy = None
----> 3 val = tf.nn.softmax_cross_entropy_with_logits(y_conv, y_)
4 cross_entropy = tf.reduce_mean(val)
5
~/anaconda/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py in softmax_cross_entropy_with_logits(_sentinel, labels, logits, dim, name)
1576 """
1577 _ensure_xent_args("softmax_cross_entropy_with_logits", _sentinel,
-> 1578 labels, logits)
1579
1580 # TODO(pcmurray) Raise an error when the labels do not sum to …Run Code Online (Sandbox Code Playgroud) 遵循Pytorch Transfer学习教程之后,我感兴趣的是仅报告训练和测试的准确性以及混淆矩阵(例如使用sklearn混淆矩阵)。我怎样才能做到这一点?当前的教程仅报告火车/ Val的准确性,我很难确定如何在其中合并sklearn混淆矩阵代码。链接到此处的原始教程:https : //pytorch.org/tutorials/beginner/transfer_learning_tutorial.html
%matplotlib inline
from graphviz import Digraph
import torch
from torch.autograd import Variable
# Author: Sasank Chilamkurthy
from __future__ import print_function, division
import torch
import torch.nn as nn
import torch.optim as optim
from torch.optim import lr_scheduler
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import copy
plt.ion()
data_transforms = {
'train': transforms.Compose([
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
'val': …Run Code Online (Sandbox Code Playgroud) python confusion-matrix scikit-learn pytorch transfer-learning
python ×6
r ×3
anaconda ×2
conda ×2
arff ×1
bitbucket ×1
csv ×1
dataframe ×1
datetime ×1
file ×1
git ×1
grep ×1
html ×1
last.fm ×1
na ×1
pandas ×1
parsing ×1
python-3.x ×1
pytorch ×1
regex ×1
scikit-learn ×1
tensorflow ×1
web-scraping ×1
windows-10 ×1