草庐IT

predict_generator

全部标签

python /R : generate dataframe from XML when not all nodes contain all variables?

考虑以下XML示例library(xml2)myxmlJohntennisgolfpythonRobertR')在这里,我想从此XML中获取一个(R或Pandas)数据框,其中包含列name和hobby。但是,如您所见,存在对齐问题,因为第二个节点中缺少hobby,而John有两个爱好。在R中,我知道如何一次提取一个特定值,例如使用xml2如下:myxml%>%xml_find_all("//name")%>%xml_text()myxml%>%xml_find_all("//hobby")%>%xml_text()但是我怎样才能在数据框中正确对齐这些数据呢?也就是说,我如何获得如下数

python - 我收到错误 <string> :149: RuntimeWarning: invalid value encountered in sqrt while generating a list

defellipse(numPoints,genX=np.linspace,HALF_WIDTH=10,HALF_HEIGHT=6.5):xs=10.*genX(-1,1,numPoints)ys=6.5*np.sqrt(1-(xs**2))return(xs,ys,"-")我收到一条错误消息,指出在平方根中遇到了无效值。我看不到它是什么。sqrt(0)=06.5*sqrt(1-(-1**2))=0它们应该可以工作,但是y值有问题,它们返回“nan” 最佳答案 可能xs**2返回一个数字>1带有负数的sqrt将返回nan(不是数字)

python - Statsmodels ARIMA - 使用 predict() 和 forecast() 的不同结果

我使用(Statsmodels)ARIMA来预测一系列的值:plt.plot(ind,final_results.predict(start=0,end=26))plt.plot(ind,forecast.values)plt.show()我以为我会从这两种方法中得到相同的结果,但我却得到了这个:我想知道是使用predict()还是forecast()。 最佳答案 从图表上看,您似乎是在使用forecast()进行样本外预测,而在使用predict进行样本内预测。基于ARIMA方程的性质,对于较长的预测周期,样本外预测往往会收敛到样

python - 如何使用 tf.estimator 返回预测和标签(使用 predict 或 eval 方法)?

我正在使用Tensorflow1.4。我创建了一个自定义的tf.estimator来进行分类,如下所示:defmodel_fn():#Someoperationshere[...]returntf.estimator.EstimatorSpec(mode=mode,predictions={"Preds":predictions},loss=cost,train_op=loss,eval_metric_ops=eval_metric_ops,training_hooks=[summary_hook])my_estimator=tf.estimator.Estimator(model_f

python - asyncio 的 call_later raises 'generator' object is not callable with coroutine object

我有一些使用call_later使用Python3.4的asyncio制作的简单代码。代码应该打印,等待10秒,然后再次打印(但是在应该执行end()时引发TypeError,见下文):importasyncio@asyncio.coroutinedefbegin():print("Startingtowait.")asyncio.get_event_loop().call_later(10,end())@asyncio.coroutinedefend():print("completed")if__name__=="__main__":try:loop=asyncio.get_eve

python - 安装工具 : How to make sure file generated by packed code be deleted by pip

我有一个名为main.py的简单代码,它在其中生成一个文件夹和一个文件:importosdefmain():path=os.path.join(os.path.dirname(__file__),'folder')ifnotos.path.isdir(path):os.mkdir(path)withopen(os.path.join(path,'file.txt'),'w+')asf:f.write('something')if__name__=='__main__':main()如果这个脚本在文件夹中运行,那么结构应该是这样的:.├──main.py└──folder└──file.

python - 何时使用 "property"内置 : auxiliary functions and generators

我最近发现了Python的propertybuilt-in,它将类方法的getter和setter伪装成类的属性。我现在很想以我非常确定不合适的方式使用它。如果类A有一个属性_x,您希望限制其允许值,那么使用property关键字显然是正确的做法;即,它将取代可能用C++编写的getX()和setX()构造。但是还有什么地方适合将函数设为属性呢?例如,如果您有classVertex(object):def__init__(self):self.x=0.0self.y=1.0classPolygon(object):def__init__(self,list_of_vertices):s

python - 类型错误 : 'generator' object has no attribute '__getitem__'

我写了一个应该返回字典的生成函数。但是,当我尝试打印一个字段时,出现以下错误printrow2['SearchDate']TypeError:'generator'objecthasnoattribute'__getitem__'这是我的代码fromcsvimportDictReaderimportpandasaspdimportnumpyasnpdefgenSearch(SearchInfo):forrow2inDictReader(open(SearchInfo)):yieldrow2train='minitrain.csv'SearchInfo='SearchInfo.csv'r

python - 值错误 : feature_names mismatch: in xgboost in the predict() function

我训练了一个XGBoostRegressor模型。当我必须使用这个经过训练的模型来预测新输入时,predict()函数会抛出feature_names不匹配错误,尽管输入特征向量与训练数据具有相同的结构。此外,为了构建与训练数据具有相同结构的特征向量,我做了很多低效的处理,例如添加新的空列(如果数据不存在),然后重新排列数据列,以便它与培训结构相匹配。是否有更好、更简洁的方式来格式化输入以使其与训练结构相匹配? 最佳答案 在这种情况下,模型构建时列名的顺序与模型评分时列名的顺序不同。我已经使用以下步骤来克服这个错误先加载pickle

python - 如何知道 Scikit-learn 中 predict_proba 的返回数组中表示哪些类

我从Scikit-learn开始......>>>importsklearn>>>sklearn.__version__'0.13.1'>>>fromsklearnimportsvm>>>model=svm.SVC(probability=True)>>>X=[[1,2,3],[2,3,4]]#featurevectors>>>Y=['apple','orange']#classes>>>model.fit(X,Y)>>>model.predict_proba([1,2,3])array([[0.39097541,0.60902459]])我怎么知道哪个类应该是哪个?