我怎样才能实现这样的大小写文本:
string="this is a string"
for case in u l c
do
declare -"${case}" out
out=$string
echo $out
done
#THIS IS A STRING
#this is a string
#This is a string
Run Code Online (Sandbox Code Playgroud)
循环遍历已声明变量的名称:
declare -u UPPER
declare -l LOWER
declare -c CAPITALIZE
for i in UPPER LOWER CAPITALIZE
do
i=$string
echo $i
done
#this is a string
#this is a string
#this is a string
Run Code Online (Sandbox Code Playgroud)
(注意全部小写)
使用以下 Python 代码SHAP summary_plot:
explainer = shap.TreeExplainer(model2)
shap_values = explainer.shap_values(X_sampled)
shap.summary_plot (shap_values, X_sampled, max_display=X_sampled.shape[1])
Run Code Online (Sandbox Code Playgroud)
并得到一个像这样的图: Python Plot
而在 R 中,绘图如下所示: R Plot
如何修改我的 Python 脚本以包含与同一图中每个特征相对应的平均值(|SHAP value|)(就像 R 输出一样)?
我有一个元组列表,我想总结哪些元素:
val t = Seq(1,2,3,4,5).map(el => (el,1))
t: Seq[(Int, Int)] = List((1,1), (2,1), (3,1), (4,1), (5,1))
t.foldLeft(0,0){ case ((a,b),(c,d)) => (a+b,c+d)}
res3: (Int, Int) = (14,6)
Run Code Online (Sandbox Code Playgroud)
答案(14,6)确实是出乎意料的(预期是(15,5))。
更令我困惑的是:
t.foldLeft(0,1){ case ((a,b),(c,d)) => (a+b,c+d)}
res3: (Int, Int) = (15,6)
Run Code Online (Sandbox Code Playgroud)
我的问题是参数foldLeft(x,y)对应于什么(它们是第一和第二折的初始参数?),以及如何在元组的第一和第二元素上获得所需的总和。
如何使用 spaCy 从句子中删除实体?我想随机删除 ORP、GPE、Money、Ordinal 或 Percent 实体。例如,
唐纳德·约翰·特朗普[人](生于 1946 年 6 月 14 日)[日期]是美国第 45 任[普通]总统和现任总统[GPE]。在进入政界之前,他是一名商人和电视名人。
现在我怎样才能从这句话中删除某个实体呢?在此示例中,函数选择删除序数实体 45th。
>>> sentence = 'Donald John Trump (born June 14, 1946) is the 45th and current president of the United States. Before entering politics, he was a businessman and television personality.'
>>> remove(sentence)
45th
Run Code Online (Sandbox Code Playgroud) 我想z从字符串开头删除重复的 's (未锚定):
string="zzz is cool"
echo ${string//"z"/""}
#is cool
Run Code Online (Sandbox Code Playgroud)
我尝试在开始时使用模式匹配进行锚定:
echo ${string##z}
#zz is cool
Run Code Online (Sandbox Code Playgroud)
我希望删除最长出现的z. 然而结果却有些“出乎意料”(不是" is cool")。
为什么?以及如何通过 bash 模式匹配获得预期的结果?
我正在做一个简单的练习,Scala试图将莫斯科时间转换为伦敦和纽约
import java.text.SimpleDateFormat
import java.util.TimeZone
inputFormat.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"))
val inMoscow = inputFormat.parse("2020-03-19 12:44 Z")
inMoscow: java.util.Date = Thu Mar 19 12:44:00 MSK 2020
Run Code Online (Sandbox Code Playgroud)
让我们尝试将时间表示形式转换为伦敦:
val outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm Z")
outputFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"))
val outLondon = outputFormat.format(inMoscow)
outputFormat: SimpleDateFormat = java.text.SimpleDateFormat@c07fb1f4
outLondon: String = "2020-03-19 09:44 +0000"
Run Code Online (Sandbox Code Playgroud)
一切正常。但是,当我尝试转换为纽约时间时,会得到意外的结果:
val outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm")
outputFormat.setTimeZone(TimeZone.getTimeZone("Americas/New_York"))
val outNY = outputFormat.format(inMoscow)
outputFormat: SimpleDateFormat = java.text.SimpleDateFormat@ba23d43a
outNY: String = "2020-03-19 09:44"
Run Code Online (Sandbox Code Playgroud)
和伦敦一样。我错过了什么?提前致谢!
对于以下代码行:
Distance1= pd.Dataframe(columns=['Lat','Lon','PSC','SC_Avg_EcNo','SC_Avg_RSCP','MaxRSCP','MaxEcNo','count','PilotPollutionFlag'])
Run Code Online (Sandbox Code Playgroud)
我收到错误:
AttributeError:模块“pandas”没有属性“Dataframe”
我见过类似的问题,大多数答案是,一个名为“pandas.py”的文件与脚本位于同一目录中,或者程序中使用了另一个名为“pd”的变量,但这并没有发生在我的程序中,那么问题是什么?
我有关于 CatBoostClassifier 的问题。
params = {
'loss_function' : 'Logloss',
'eval_metric' : 'AUC',
'verbose' : 200,
'random_seed' : 42,
'custom_metric' : 'AUC:hints=skip_train~false'
}
cbc = CatBoostClassifier(**params)
cbc.fit(x_tr, y_tr,
eval_set = (x_te, y_te),
use_best_model = True,
plot = True
);
predictions = cbc.predict(x_te)
Run Code Online (Sandbox Code Playgroud)
模型结果:
最佳测试 = 0.6786987522
但是当我尝试时:
from sklearn import metrics
auc = metrics.roc_auc_score(y_te, predictions)
auc
Run Code Online (Sandbox Code Playgroud)
我得到了0.5631684491978609结果。为什么这个结果不同?第一个和第二个结果是什么意思?哪一项是我的 cbc 模型的最终指标?