小编Rah*_*wal的帖子

使用ReporteRs软件包使用R Shiny生成powerpoint幻灯片

我有一个R闪亮的代码,可以生成各种报告,文字云,情感分析和各种其他内容.现在我希望通过点击一个按钮,所有这些生成的报告都可以一次性下载并附加到ppt.所以,例如它应该看起来像:

幻灯片1:词云

幻灯片2:情绪分析

幻灯片3:报告1 ......等等

到现在为止,我可以单独下载所有这些报告,即我的Shiny UI中有不同的选项卡,每个报告都可以找到并点击"下载",然后由downloadHandler下载.

此外,只需点击一下,我就可以用一个pdf下载所有这些报告,即在一个页面中我有报告1,依此类推.

直到现在我已达到以下:

    #downloadReport is my action button
    #on click of this button I am expecting the ppt. to be downloaded
    observeEvent(input$downloadReport, {
    # Create a PowerPoint document
    doc = pptx( )

    # Slide 1 : Title slide
    #+++++++++++++++++++++++
    doc <- addSlide(doc, "Title Slide")
    doc <- addTitle(doc,"Create a PowerPoint document from R software")
    doc <- addSubtitle(doc, "R and ReporteRs package")


   # Slide 2 : Add Word Cloud
    #+++++++++++++++++++++++
    doc <- addSlide(doc, "Title …
Run Code Online (Sandbox Code Playgroud)

r shiny shiny-server reporters shinydashboard

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

使用rpart的预测方法(R编程)计算树的预测精度

我使用rpart为数据集构建了一个决策树.

然后我将数据分为两部分 - 训练数据集和测试数据集.已使用训练数据为数据集构建树.我想根据创建的模型计算预测的准确性.

我的代码如下所示:

library(rpart)
#reading the data
data = read.table("source")
names(data) <- c("a", "b", "c", "d", "class")

#generating test and train data - Data selected randomly with a 80/20 split
trainIndex  <- sample(1:nrow(x), 0.8 * nrow(x))
train <- data[trainIndex,]
test <- data[-trainIndex,]

#tree construction based on information gain
tree = rpart(class ~ a + b + c + d, data = train, method = 'class', parms = list(split = "information"))
Run Code Online (Sandbox Code Playgroud)

我现在想要通过将结果与实际值训练和测试数据进行比较来计算模型生成的预测的准确性,但是这样做时我遇到了错误.

我的代码如下所示:

t_pred = predict(tree,test,type="class")
t = test['class'] …
Run Code Online (Sandbox Code Playgroud)

r machine-learning decision-tree rpart

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

获取 someUrl.html 在 React Native / Expo 中不起作用?

我正在尝试使用 fetch 来获取 React Native 中 HTML 页面的内容,并且我正在 expo 上运行它,在这里:

\n\n

https://snack.expo.io/@abalja/hellofetch

\n\n

基本上,代码没什么特别的,使用“fetch”,它确实适用于加载 .json 文件,但我无法让它适用于 .html 文件。它只是默默地失败了,我什至没有记录错误。我不确定这是 Expo 还是 ReactNative 问题。

\n\n
const url2 = \'http://www.spiegel.de/sport/fussball/nations-league-italien-trifft-in-der-nachspielzeit-polen-steigt-ab-a-1233219.html#ref=rss\'\n\nexport default class App extends React.Component {\n  componentDidMount(){\n\n    console.log(\'did mount, fetching: \' + url2)\n    fetch(url2)\n        .then((response) => {\n          console.log(response) // 1\n          return response.text()\n        })\n        .then((responseText) => {\n          console.log(\'fetch text\', responseText) // 2\n          // return responseText.movies;\n        })\n        .catch((error) => {\n          console.error(error);\n        });\n  }\n  render() {\n    return (\n      <View style={styles.container}>\n\n      </View>\n    );\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 1 …

fetch react-native expo

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

带Lambda函数和标量的Dict理解

我对lambda函数和标量有dict理解:

d = {k: lambda x : x.sum() if 'a' in k else 'yes' for k in ['bac','sss','asa']}
print (d)
{'bac': <function <dictcomp>.<lambda> at 0x00000000031891E0>, 
 'sss': <function <dictcomp>.<lambda> at 0x000000000D887EA0>, 
 'asa': <function <dictcomp>.<lambda> at 0x000000000D887B70>}
Run Code Online (Sandbox Code Playgroud)

如果需要两个标量,则可以很好地工作:

d = {k: 'no' if 'a' in k else 'yes' for k in ['bac','sss','asa']}
print (d)
{'bac': 'no', 'sss': 'yes', 'asa': 'no'}
Run Code Online (Sandbox Code Playgroud)

预期输出-标量和lambda函数的组合:

print (d)
{'bac': <function <dictcomp>.<lambda> at 0x00000000031891E0>, 
 'sss': 'yes', 
 'asa': <function <dictcomp>.<lambda> at 0x000000000D887B70>}
Run Code Online (Sandbox Code Playgroud)

怎么了?为什么不起作用?正确的方法是什么?

python lambda dictionary python-3.x dictionary-comprehension

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

如何手动安装 nltk 停用词包

这是我的代码:

from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

example_sent = "This is a sample sentence, showing off the stop words filtration."

stop_words = set(stopwords.words('english'))

word_tokens = word_tokenize(example_sent)

filtered_sentence = [w for w in word_tokens if not w in stop_words]

filtered_sentence = []

for w in word_tokens:
    if w not in stop_words:
        filtered_sentence.append(w)


print(word_tokens)
print(filtered_sentence)
Run Code Online (Sandbox Code Playgroud)

但是在运行代码时,我收到此错误:

Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource
Run Code Online (Sandbox Code Playgroud)

如果我下载NLTK Downloader,我会收到以下错误:

[nltk_data] Error loading popular: <urlopen error [WinError …
Run Code Online (Sandbox Code Playgroud)

python-3.x

3
推荐指数
1
解决办法
5569
查看次数

非法状态:无法加载指令 AppComponent 的摘要

我正在用 Angular 编写一个 spec.ts 文件并收到以下错误:

失败:非法状态:无法加载指令 AppComponent 的摘要。

下面是我尝试过的代码

import { TestBed, async } from "@angular/core/testing";
    import { AppComponent } from "./app.component";

    describe('AppComponent', () => {
        beforeEach(() => {
            TestBed.configureTestingModule({
                declarations: [
                    AppComponent
                ],
            });
        });
    });

    it('should create the app', async(() => {
        let fixture = TestBed.createComponent(AppComponent);
        let app = fixture.debugElement.componentInstance;
        expect(app).toBeTruthy();
    }));``
Run Code Online (Sandbox Code Playgroud)

angular6

3
推荐指数
1
解决办法
7815
查看次数

如何使用 pandas 将 csv 文件读入数据框

我刚刚得到一个 csv 文件,我想使用 pandas 将数据集加载为数据框。但是,我对这种数据格式有点困惑。

这是两行数据的示例:

Name=John, Gender=M, BloodType=A, Location=New York, Age=18
Name=Mary, Gender=F, BloodType=AB, Location=Seatle, Age=30
Run Code Online (Sandbox Code Playgroud)

如何将此数据集加载到包含列(姓名、性别、血型等)的数据框中?

如果有人给我一些入门建议,我将不胜感激!

python-3.x opencsv pandas

3
推荐指数
1
解决办法
4439
查看次数

Unpivot df columns to multiple columns and rows

I have a df like this:

Country  Industry   2011_0-9_AF    2011_0-9_AP
US        AB            0               0
US        AC           12.34           12.4
UK        AB            1               2
UK        AC            12              5
Run Code Online (Sandbox Code Playgroud)

So, in my original dataframe I have 3 countries for every country I have 4 industries and I have 1120 columns like 2011_0-9_AF etc.

I need to transform the df like this:

Country  Industry   Year   Group_Type    Tags    Value
US        AB         2011   0-9          AF      0
US        AB         2011   0-9          AP      0
US        AC         2011   0-9 …
Run Code Online (Sandbox Code Playgroud)

python pivot pandas

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

pandas 中的 scatter_matrix 返回大量文本 - 如何删除它?

当我使用 pandas 的 scatter_matrix 函数时,我得到了很多类似的文本

array([[<matplotlib.axes._subplots.AxesSubplot object at 0x000001BD9F985860>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000001BD9F9C0588>,
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何告诉熊猫不要返回此文本?

python visualization pandas

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

KDB:我如何在 2 个列表上执行减号

输入:

a: 1 2 3 4 5 
b: 5 2 6 7
Run Code Online (Sandbox Code Playgroud)

我需要做什么操作才能删除 a 中 b 的所有元素?

预期输出:

1 3 4
Run Code Online (Sandbox Code Playgroud)

kdb

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