我已经在django中创建了一个应用程序,我知道django rest框架用于API.但是当我开始在他们的网站上阅读关于django rest框架的时候.API 指南中的每个东西(如请求,响应,视图等)关于它的.talks优于django(请求,回复,观点等)
我不明白这些API是否会取代我现有的django模型,视图等,或者我如何在现有的django代码中以不同方式使用它们
我对django非常熟悉,但是在花了一些时间后才能理解django rest框架究竟是什么.(我知道它用于API)我也确实需要一个API.我的应用程序能够发送数据到没有API的服务器,所以在什么情况下我需要一个API
这可能不是一个合适的论坛,但我想了解查询中发生的逻辑错误。
我在下面的查询中写道,以了解有多少用户传递的邮件大于发送的邮件(可能是数据捕获中的错误,只是想对其进行评估)。
SELECT COUNT(DISTINCT user_id)
FROM wk_24_trigger
UNION
SELECT COUNT(DISTINCT user_id)
FROM (
SELECT *, (CASE WHEN delivered > 0 THEN 1 ELSE 0 END) as D,
(CASE WHEN sent > 0 THEN 1 ELSE 0 END) as S
FROM wk_24_trigger) t
WHERE t.D > t.s
Run Code Online (Sandbox Code Playgroud)
我得到的结果如下
_c0
1 1056840
2 1819729
Run Code Online (Sandbox Code Playgroud)
我不明白为什么第2行>第1行。
理想情况下,即使对于已发送的每个条目>发送,第2行和第1行也应该相同
我试图在随机森林回归器的帮助下解决波士顿数据集上的回归问题。我正在使用GridSearchCV来选择最佳超参数。
问题一
我应该适合GridSearchCV一些X_train, y_train,然后获得最佳参数。
或者
我应该适合它X, y以获得最佳参数。(X,y =整个数据集)
问题二
说如果我适合它X, y并获得最佳参数,然后在这些最佳参数上建立一个新模型。现在我应该如何训练这个新模型?
我应该在X_train, y_train或上训练新模型X, y.
问题三
如果我训练新模型,X,y那么我将如何验证结果?
到目前为止我的代码
#Dataframes
feature_cols = ['CRIM','ZN','INDUS','NOX','RM','AGE','DIS','TAX','PTRATIO','B','LSTAT']
X = boston_data[feature_cols]
y = boston_data['PRICE']
Run Code Online (Sandbox Code Playgroud)
训练测试数据拆分
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 1)
Run Code Online (Sandbox Code Playgroud)
网格搜索以获得最佳超参数
from sklearn.grid_search import GridSearchCV
param_grid = {
'n_estimators': [100, 500, 1000, 1500],
'max_depth' : [4,5,6,7,8,9,10]
}
CV_rfc = …Run Code Online (Sandbox Code Playgroud) python machine-learning random-forest scikit-learn grid-search
我在sklearn 的帮助下尝试在波士顿数据集上使用随机森林算法来预测房价。我尝试如下medvRandomForestRegressor3 iterations
迭代 1:使用具有默认超参数的模型
#1. import the class/model
from sklearn.ensemble import RandomForestRegressor
#2. Instantiate the estimator
RFReg = RandomForestRegressor(random_state = 1, n_jobs = -1)
#3. Fit the model with data aka model training
RFReg.fit(X_train, y_train)
#4. Predict the response for a new observation
y_pred = RFReg.predict(X_test)
y_pred_train = RFReg.predict(X_train)
Run Code Online (Sandbox Code Playgroud)
迭代 1 的结果
{'RMSE Test': 2.9850839211419435, 'RMSE Train': 1.2291604936401441}
Run Code Online (Sandbox Code Playgroud)
迭代 2:我使用RandomizedSearchCV来获得超参数的最佳值
from sklearn.ensemble import RandomForestRegressor
RFReg = RandomForestRegressor(n_estimators = 500, random_state …Run Code Online (Sandbox Code Playgroud) python machine-learning random-forest scikit-learn grid-search
我有一个数据框,如下所示
df = pd.DataFrame({
"Junk":list("aaaaaabbbcccc"),
"Region":['West','West','West','West','East','East','East','South','South','South','North','North','North'],
"Sales":[1, 3, 4, 2, 4, 2, 5, 7, 9, 7, 5, 9, 5]
})
+------+--------+-------+
| Junk | Region | Sales |
+------+--------+-------+
| a | West | 1 |
| a | West | 3 |
| a | West | 4 |
| a | West | 2 |
| a | East | 4 |
| a | East | 2 |
| b | East | 5 |
| b …Run Code Online (Sandbox Code Playgroud) 我有一个数据库,其在SAS中导入后的大小约为600mb.
(我OPTIONS COMPRESS = YES在程序开始时使用)
然后我派出一些列/变量,得到一个大小约为800 mb的最终数据库
最终数据库有 1929743 observations
我想要的是
我想按照最终数据库中列中每条记录的descending顺序对数据进行排序PUBLICATION_DATEITEM
我的代码到目前为止
PROC SORT DATA=newdb.access_db OUT= newdb.access_sorted;
BY ITEM DESCENDING PUBLICATION_DATE;
RUN;
Run Code Online (Sandbox Code Playgroud)
我得到的错误
ERROR: No disk space is available for the write operation. Filename =
C:\Users\AB364273\AppData\Local\Temp\SAS Temporary
Files\SAS_util00010000204C_A00DVDPCSAS2007\ut204C000008.utl.
ERROR: Failure while attempting to write page 134 of sorted run 11.
ERROR: Failure while attempting to write page 40544 to utility file 1.
ERROR: Failure encountered while creating initial set of sorted runs.
ERROR: …Run Code Online (Sandbox Code Playgroud) 在我使用 Gridster 的应用程序中,我正在更改小部件位置,然后将其保存为 json 变量。我想将此 json 变量存储在 django 数据库中。为此,我不明白我应该如何在 views.py 中定义一个函数,在 models.py 中定义一个可以存储 json 变量的类
我的 HTML/JS 模板是
var URL = "{% url 'my_view_url' %}";
$('.js-seralize-update').on('click', function () {
var s = gridster.serialize();
updated_grid=JSON.stringify(s);
$('#log').val(updated_grid);
function updategridster(){
var data = updated_grid;
$.post(URL, data, function(response){
if(response === 'success'){ alert('Yay!'); }
else{ alert('Error! :('); }
});
}
});
Run Code Online (Sandbox Code Playgroud)
我的意见.py
def save_grid(request):
if request.method == 'POST':
# Some code to get json variable and store it to model
return HttpResponse('success') # if everything …Run Code Online (Sandbox Code Playgroud) python ×4
django ×2
grid-search ×2
scikit-learn ×2
dataframe ×1
json ×1
pandas ×1
sas ×1
sorting ×1
sql ×1