小编Ker*_*mit的帖子

如何调整数据表的大小以适合shinyDashboard的box()

我不知道如何确定DT::renderDataTable我的盒子适合我的尺寸。

这是我的闪亮渲染的图片

在此输入图像描述

有人知道如何确保桌子适合盒子吗?或者我可以在表格下方添加一个滑块来滚动屏幕上没有的其他变量吗?

这是我的代码:

服务器R

output$table = DT::renderDataTable({
    DT::datatable(
      round(df,2), 
      rownames = TRUE,
      extensions = 'Buttons',
      options = list(
        autoWidth = FALSE, 
        columnDefs = list(list(width = "125px", targets = "_all")),
        dom = 'tpB',
        lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
        pageLength = 15,
        buttons = list(
          list(
            extend = "collection",
            text = 'Show More',
            action = DT::JS("function ( e, dt, node, config ) {
                              dt.page.len(50);
                              dt.ajax.reload();}")
          ),list(
            extend = "collection",
            text = 'Show Less',
            action = DT::JS("function …
Run Code Online (Sandbox Code Playgroud)

r shiny shinydashboard

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

如何在 Python scikit-learn 中输出随机森林中每棵树的回归预测?

我是 scikit-learn 和随机森林回归的新手,想知道除了组合预测之外,是否有一种简单的方法可以从随机森林中的每棵树获得预测。

基本上我想在 R 中使用该predict.all = True选项可以做什么。


# Import the model we are using
from sklearn.ensemble import RandomForestRegressor
# Instantiate model with 1000 decision trees
rf = RandomForestRegressor(n_estimators = 1000, random_state = 1337)
# Train the model on training data
rf.fit(train_features, train_labels)
# Use the forest's predict method on the test data
predictions = rf.predict(test_features)
print(len(predictions)) #6565 which is the number of observations my test set has.
Run Code Online (Sandbox Code Playgroud)

我想对每棵树进行每一次预测,而不仅仅是每个预测的平均值。

可以在python中做到吗?

python regression machine-learning random-forest scikit-learn

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

从 XGBoost 保存树

我正在尝试将 XGBoost 的决策树保存为.png文件。当我使用随机森林执行此操作时效果很好,但它不适用于我的 XGBoost

我有以下代码:

import xgboost as xgb
from sklearn.tree import export_graphviz

import warnings
warnings.filterwarnings('ignore')

from sklearn.metrics import mean_absolute_error
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from math import sqrt

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
from sklearn import metrics

from sklearn.preprocessing import LabelEncoder


# Using Skicit-learn to split data into training and testing sets
from sklearn.model_selection import train_test_split

df = pd.read_csv("data_clean.csv")
del df["Unnamed: 0"]

df = df[["gross_square_feet","block","land_square_feet","lot","age_of_building","borough","residential_units","commercial_units","total_units","sale_price"]]

df['borough'] = …
Run Code Online (Sandbox Code Playgroud)

python machine-learning graphviz scikit-learn xgboost

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