我发现了 ggplot 和 ggplotly 中同一个图表之间有趣而奇怪的区别
income_gap_chart <- ggplot(income_gap, aes(x = Country, y = Percent, fill = Income)) +
geom_bar(position = "dodge", stat = "identity") +
scale_fill_brewer(palette = "Set1") +
coord_flip() +
theme(axis.title.y = element_blank()) +
scale_y_continuous(limits = c(0, 100)) +
theme_tufte() +
theme(axis.title.y = element_blank()) +
theme(legend.position = "bottom")
Run Code Online (Sandbox Code Playgroud)
对于 ggplot 它看起来很完美,底部有一个图例标题
但是当我用 ggplotly() 包装它时,图例开始表现不同
我的问题 - 我想要 ggplotly 格式的第一个图表,但无法解决这个问题,底部的图例不起作用。想法?
谢谢!
我有一个数据框,是我在 pandas 中创建的,按日期分组并按游乐设施进行总结。
date rides
0 2019-01-01 247279
1 2019-01-02 585996
2 2019-01-03 660631
3 2019-01-04 662011
4 2019-01-05 440848
.. ... ...
451 2020-03-27 218499
452 2020-03-28 143305
453 2020-03-29 110833
454 2020-03-30 207743
455 2020-03-31 199623
[456 rows x 2 columns]
Run Code Online (Sandbox Code Playgroud)
我的date专栏在datetime64[ns].
date datetime64[ns]
rides int64
dtype: object
Run Code Online (Sandbox Code Playgroud)
现在我想创建另一个数据框,按月份和年份分组(我有 2019 年和 2020 年的数据)并按乘车次数进行汇总。
理想输出:
Year Month Rides
2019 January 2000000
2020 March 1000000
Run Code Online (Sandbox Code Playgroud) 我正在尝试重写这段不久前编写的代码。
它有多个块,因此,我将其分成更小的块并逐步重写。例如,转换.ix为iloc等。
这个块给了我一个错误:
#Loop through all rows, skip the user column, and fill with similarity scores
for i in range(0,len(data_sims.index)):
for j in range(1,len(data_sims.columns)):
user = data_sims.index[i]
product = data_sims.columns[j]
if data.iloc[i][j] == 1:
data_sims.iloc[i][j] = 0
else:
product_top_names = data_neighbours.iloc[product][1:10]
product_top_sims = data_ibs.iloc[product].order(ascending=False)[1:10]
user_purchases = data_germany.iloc[user,product_top_names]
data_sims.iloc[i][j] = getScore(user_purchases,product_top_sims)
Run Code Online (Sandbox Code Playgroud)
出现错误
TypeError: Cannot index by location index with a non-integer key
Run Code Online (Sandbox Code Playgroud)
我想这里有一些东西需要更新,但找不到具体是什么。我不认为这与数据有关。这只是更新代码。
感谢任何提示!
无法解决 MULTIPLE 过滤器/多边形的问题。目前我的代码有效,但速度很慢,我不使用observe()、reactive() 和 LeafletProxy(),因为我偶然发现了。
我显然检查了这个答案根据输入更改传单地图而无需重绘 和这个在不重绘传单地图和传单教程的情况下进行闪亮的 UI 调整 使用带有闪亮的传单
就我而言,我有四个过滤器,但不太明白如何将它们组合在一起并使地图快速。
我的样本数据:
Country Client Channel Status
Country 1 Client 1 Agent network Launched
Country 2 Client 2 Debit cards Launched
Country 3 Client 3 M-banking Planning
Country 4 Client 4 M-banking Launched
Country 5 Client 5 Agent network Launched
Country 6 Client 6 Agent network Launched
Country 7 Client 7 Agent network Pilot
Run Code Online (Sandbox Code Playgroud)
此代码有效
# Packages
library(shiny)
library(shinythemes)
library(leaflet)
library(rgdal)
# Set working …Run Code Online (Sandbox Code Playgroud) 我正在使用 PyCaret 并收到错误消息。
AttributeError: 'SimpleImputer' object has no attribute '_validate_data'
Run Code Online (Sandbox Code Playgroud)
尝试创建一个基本实例。
# Create a basic PyCaret instance
import pycaret
from pycaret.regression import *
mlb_pycaret = setup(data = pycaret_df, target = 'pts', train_size = 0.8, numeric_features = ['home',
'first_time_pitcher'], session_id = 123)
Run Code Online (Sandbox Code Playgroud)
我所有的变量都是数字的(我强制了其中的两个,它们是布尔值)。我的目标变量是label,这是默认值。
我还安装了PyCaret,导入了它的回归,然后重新安装scikit learn,导入SimpleImputer为from sklearn.impute import SimpleImputer
OBP_avg Numeric
SLG_avg Numeric
SB_avg Numeric
RBI_avg Numeric
R_avg Numeric
home Numeric
first_time_pitcher Numeric
park_ratio_OBP Numeric
park_ratio_SLG Numeric
SO_avg_p Numeric
pts_500_parkadj_p Numeric
pts_500_parkadj Numeric …Run Code Online (Sandbox Code Playgroud) 我有一个数据框
df = {'Month': [1, 8], 'Year': [2015, 2020]}
df = pd.DataFrame(data = df)
df
Run Code Online (Sandbox Code Playgroud)
想将它变异为一个新列。
期望的输出:
df = {'Month': [1, 8], 'Year': [2015, 2020], 'Quarter': ['Q12015', 'Q32020']}
df = pd.DataFrame(data = df)
df
Run Code Online (Sandbox Code Playgroud)
也将不胜感激评论什么是处理这些数据以使用scikit-learn. 现在我正在考虑没有虚拟变量的字符串和分类变量,但感谢这里的任何提示。谢谢!
我有一个包含 15 个不平衡类别的数据集,并尝试使用 keras 进行多标签分类。
我正在尝试使用微型 F-1 分数作为衡量标准。
我的型号:
# Create a VGG instance
model_vgg = tf.keras.applications.VGG19(weights = 'imagenet', pooling = 'max', include_top = False,
input_shape = (512, 512, 3))
# Freeze the layers which you don't want to train.
for layer in model_vgg.layers[:-5]:
layer.trainable = False
# Adding custom Layers
x = model_vgg.output
x = Flatten()(x)
x = Dense(1024, activation = "relu")(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation = "relu")(x)
predictions = Dense(15, activation = "sigmoid")(x)
# creating …Run Code Online (Sandbox Code Playgroud) 试过很多选择,但都失败了.被迫在这里问.我的日期/时间是1/1/2016 0:00格式.
所以,我试过了
start.time <- citi.bike$starttime
head(start.time)
start.date <- strftime(as.Date(start.time), format="%m/%d/%Y")
head(start.date)
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但我的日期看起来像 "01/20/0001""01/20/0001""01/20/0001""01/20/0001""01/20/0001""01/20/0001".
所有的日子都变成了"20".
为什么?
我用 Python 拟合了基本的 LGBM 模型。
\n# Create an instance\nLGBM = LGBMRegressor(random_state = 123, importance_type = \'gain\') # `split` can be also selected here\n\n# Fit the model (subset of data)\nLGBM.fit(X_train_subset, y_train_subset)\n\n# Predict y_pred\ny_pred = LGBM.predict(X_test)\nRun Code Online (Sandbox Code Playgroud)\n我正在查看文档:
\n\n\nimportant_type(字符串,可选(默认=“split”))\xe2\x80\x93 如何计算\n重要性。如果 \xe2\x80\x9csplit\xe2\x80\x9d,\n结果包含该特征在模型中使用的次数。如果\xe2\x80\x9cgain\xe2\x80\x9d,结果包含使用该功能的分割的总\n增益。
\n
我使用了gain它,它打印了我的总收益。
# Print features by importantce\npd.DataFrame([X_train.columns, LGBM.feature_importances_]).T.sort_values([1], ascending = [True])\n\n 0 1\n\n59 SLG_avg_p 0\n4 PA_avg 2995.8\n0 home 5198.55\n26 next_home 11824.2\n67 first_time_pitcher 15042.1\netc\nRun Code Online (Sandbox Code Playgroud)\n我试过:
\n# get importance\nimportance = LGBM.feature_importances_\n# summarize feature importance\nfor …Run Code Online (Sandbox Code Playgroud) 我尝试了这个问题的所有三个解决方案来解决问题,但仍然收到错误:
ImportError: cannot import name 'ToTensorV2' from 'albumentations.pytorch' (/usr/local/lib/python3.7/dist-packages/albumentations/pytorch/__init__.py)
Run Code Online (Sandbox Code Playgroud)
我目前的代码:
!pip install -U albumentations
import albumentations
from albumentations.pytorch import ToTensorV2
Run Code Online (Sandbox Code Playgroud) 作为一个可怜的闪亮男人,无法解决一个简单的任务。
我在带有日期的数据框中有一行
crime.date <- strptime(incidents$REPORT_DAT, format = "%Y-%m-%d")
Run Code Online (Sandbox Code Playgroud)
我的日期输出看起来像这样。
[1] "2017-04-07 EDT" "2017-03-13 EDT" "2017-01-08 EST" "2017-01-25 EST" "2017-
01-03 EST" "2017-01-03 EST" "2017-01-03 EST"
[8] "2017-01-03 EST" "2017-01-03 EST" "2017-01-03 EST" "2017-01-03 EST" "2017-
01-04 EST" "2017-01-03 EST" "2017-01-03 EST"
Run Code Online (Sandbox Code Playgroud)
现在,我尝试形象化此过滤器选择的所有犯罪的选择。
# USER INTERFACE CODE
ui <- fluidPage(
titlePanel("Washington, DC crimes by date"),
column(4, wellPanel(
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = crime.date , end = crime.date
)
)),
column(6,
verbatimTextOutput("dateRange")
)
)
# SERVER CODE
server …Run Code Online (Sandbox Code Playgroud)