我知道这是一个非常经典的问题,可能会在本论坛中多次回答,但是我找不到任何明确的答案从头开始清楚地解释这一点。
首先,我的数据集 my_data 有 4 个变量,例如 my_data = variable1、variable2、variable3、target_variable
所以,让我们来解决我的问题。我将解释我的所有步骤,并就我遇到的问题寻求您的帮助:
# STEP1 : split my_data into [predictors] and [targets]
predictors = my_data[[
'variable1',
'variable2',
'variable3'
]]
targets = my_data.target_variable
# STEP2 : import the required libraries
from sklearn import cross_validation
from sklearn.ensemble import RandomForestRegressor
#STEP3 : define a simple Random Forest model attirbutes
model = RandomForestClassifier(n_estimators=100)
#STEP4 : Simple K-Fold cross validation. 3 folds.
cv = cross_validation.KFold(len(my_data), n_folds=3, random_state=30)
# STEP 5
Run Code Online (Sandbox Code Playgroud)
在这一步,我想根据训练数据集拟合我的模型,然后在测试数据集上使用该模型并预测测试目标。我还想计算所需的统计数据,例如 MSE、r2 等,以了解我的模型的性能。
如果有人帮助我了解 Step5 的一些基本代码行,我将不胜感激。
regression machine-learning random-forest scikit-learn cross-validation
现在我使用 rest_auth 重置密码,无论发送的电子邮件和 URL 像这样打开,但我在其上添加值:这是我单击电子邮件中发送的 URL 时的页面:

在填写字段并提出发布请求后,我得到了这个:这是我得到的错误:

这是我的网址:
urlpatterns = [
path('', include('rest_auth.urls')),
path('login/', LoginView.as_view(), name='account_login'),
path('registration/', include('rest_auth.registration.urls')),
path('registration/', RegisterView.as_view(), name='account_signup'),
re_path(r'^account-confirm-email/', VerifyEmailView.as_view(),
name='account_email_verification_sent'),
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', VerifyEmailView.as_view(),
name='account_confirm_email'),
re_path(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(),
name='password_reset_confirm')
]
Run Code Online (Sandbox Code Playgroud)
视图是但它内置于 rest_auth 中:
class PasswordResetConfirmView(GenericAPIView):
"""
Password reset e-mail link is confirmed, therefore
this resets the user's password.
Accepts the following POST parameters: token, uid,
new_password1, new_password2
Returns the success/fail message.
"""
serializer_class = PasswordResetConfirmSerializer
permission_classes = (AllowAny,)
@sensitive_post_parameters_m
def dispatch(self, *args, **kwargs):
return super(PasswordResetConfirmView, self).dispatch(*args, **kwargs)
def …Run Code Online (Sandbox Code Playgroud) django django-rest-framework django-allauth django-rest-auth
我有一个应用程序,需要将其限制为少数几个 IP。我可以编写一个中间件,如果请求 IP 不在允许列表中,则返回,但是我希望这个过程尽可能高效。即我想尽早断开连接。我最早可以在什么阶段断开连接,最好是通过 HTTP 响应。我无法控制主机防火墙或边界防火墙来过滤流量,并且即使我控制了防火墙,我也无法提供 HTTP 响应。
另外,我希望能够获得 gin 中 HTTP 请求生命周期的描述。
当我在 VPS 中运行 npm run prod 时,我一遍又一遍地遇到相同的错误。我的本地开发机器没有问题:
这是错误消息,我的应用程序是带有 Vue 的 Laravel 应用程序,我用它laravel-mix来编译我的资产,我的生产开发人员是带有 Ubuntu 和 LEMP 堆栈的 DigitalOcean VPS:
$ npm run prod
> @ prod /var/www/dtcburger.es
> npm run production
> @ production /var/www/dtcburger.es
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
internal/child_process.js:313
throw errnoException(err, 'spawn');
^
Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:313:11)
at exports.spawn (child_process.js:508:9)
at Object.exports.fork (child_process.js:109:10)
at fork (/var/www/dtcburger.es/node_modules/worker-farm/lib/fork.js:17:36)
at Farm.startChild (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:106:16)
at Farm.processQueue (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:279:10)
at Farm.<anonymous> (/var/www/dtcburger.es/node_modules/worker-farm/lib/farm.js:97:21)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout …Run Code Online (Sandbox Code Playgroud) 我正在使用 NetworkX 来可视化一个包含 > 1000 个节点的大图。作为可视化的一部分,我希望能够突出显示某些节点。
我已经看到了这个问题,并且知道 NetworkX 将允许您通过更改节点颜色来突出显示节点,如下所示:
import networkx as nx
import matplotlib.pyplot as plt
edges = [['A','B'], ['A','C'], ['A','D'], ['B','E'], ['B','F'], ['D','G'],['D','H'],['F','I'],['G','J'],['A','K']]
G = nx.Graph()
G.add_edges_from(edges)
colours = ['blue']*5 + ['red'] + ['blue']*5
nx.draw_networkx(G, font_size=16, node_color=colours)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是,对于大量节点,我不得不显着减小节点大小,否则它只会显示为重叠节点的模糊云,因此更改节点颜色无效。
理想情况下,我想要做的是将标签字体颜色更改为,例如,所选节点的文本标签的红色。node_color然而,NetworkX 似乎只提供一个全局参数font_color来更改所有节点标签的颜色,它不会t 接受,例如font_color=colours。
如果有任何方法可以通过 NetworkX 或 Matplotlib 更改特定节点/节点组的字体颜色,或添加任何类型的标注,或以任何其他方式突出显示某些节点而不依赖于更改node_color?
df = pd.DataFrame({'Last_Name': ['Smith', Null, Null,'Joy'],
'First_Name': ['John', Null, 'Bill', 'Tony'],
'Age': [35, 45, Null, 60]})
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到的只是零计数First_Name和Age不Last_Name?我正在做类似下面的事情,但它正在获取所有列的所有空计数。
null_counts = irs_df.isnull().sum()
null_counts[null_counts > 0].sort_values(ascending=False)
Run Code Online (Sandbox Code Playgroud)
如何过滤掉Last_Name?
我正在使用 MongoDB 和猫鼬。我目前有一个like按钮,当我单击它时,我想增加文档中的“喜欢”字段。目前我的文档具有以下架构:
brote {
name:
content:
created:
likes:
}
Run Code Online (Sandbox Code Playgroud)
并且我已经测试过我的查询中的 ID 与我的数据库中的对象的 ID 相匹配。
我咨询了如何在 Mongoose 中增加 Number 值?并用猫鼬增加值?但这些解决方案似乎没有对我的数据库进行任何更改。也许有一些显而易见的东西我失踪了?
索引.js
mongoose.connect('mongodb://localhost:27017/bromies', { useUnifiedTopology: true, useNewUrlParser: true });
mongoose.set('useFindAndModify', false);
var Brote = mongoose.model('Brote', broteFormSchema);
app.post('/likes', (req, res) => {
let query = { id: req.body._id};
Brote.findOneAndUpdate(query, {$inc: { 'likes': 1 }});
})
Run Code Online (Sandbox Code Playgroud) a = False
while a == False:
quant = int(input("Input the size:\n"))
if type(quant) == int:
a = True
else:
print('Please use numbers:\n')
a = False
Run Code Online (Sandbox Code Playgroud)
我试图让用户无法输入字符,但如果输入,它会打印出第二条消息。但是,当我尝试输入字符时,会出现以下消息:
Traceback (most recent call last):
File "C:/Users/user/Desktop/pythonproject1/Actual Projects/password
generator/Password_generator.py", line 34, in <module>
quant = int(input("Input the:\n"))
ValueError: invalid literal for int() with base 10: 'thisiswhatIwrote'
Run Code Online (Sandbox Code Playgroud)
输入整数时它工作正常。我试过isinstance()and is_integer(),但无法让它们工作,所以只是试图让它变得简单。
python ×3
django ×1
express ×1
go ×1
go-gin ×1
matplotlib ×1
middleware ×1
mongodb ×1
mongoose ×1
networkx ×1
node.js ×1
npm ×1
pandas ×1
regression ×1
scikit-learn ×1