我正在为我的 ML 模型使用 FAST API。
我有一个管道。
lr_tfidf = Pipeline([('vect', tfidf),
('clf', LogisticRegression(penalty='l2'))])
Run Code Online (Sandbox Code Playgroud)
现在在 Fast API 中,当我想要预测并将结果显示为 API 时,我的代码是
app = FastAPI()
@app.post('/predict')
def predict_species(data: str):
data = np.array([data])
prob = lr_tfidf.predict_proba(data).max()
pred = lr_tfidf.predict(data)
return {'Probability': f'{prob}',
'Predictions':f'{pred}'}
Run Code Online (Sandbox Code Playgroud)
我是从教程里复制过来的。当我通过 FASTAPI 在 GUI 上测试它时,它工作得很好,如图所示,即它显示了概率和预测。
当我转到 GUI 提供的请求 URL 时http://127.0.0.1:8000/predict?data=hello(测试数据是 hello),它给了我错误。
{"detail":"Method Not Allowed"}
Run Code Online (Sandbox Code Playgroud)
在我的终端上,错误消息是
INFO: 127.0.0.1:42568 - "GET /predict?data=hello HTTP/1.1" 405 Method Not Allowed
Run Code Online (Sandbox Code Playgroud) 我正在使用提示数据集,这是数据集的头部。
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
Run Code Online (Sandbox Code Playgroud)
我的代码是
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3 …Run Code Online (Sandbox Code Playgroud) 我下载了 netbeans ide 11 并尝试做一个示例 hello world 项目,但它给了我错误“无法访问 java.lang 致命错误:无法在类路径或引导类路径中找到包 java.lang”我尝试了一些堆栈溢出的解决方案,但没有工作。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author ahmad
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello");
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个简单的神经网络
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, MaxPool2D
model = Sequential([
Conv2D(16,(3,3),padding='same', input_shape=(1,28,28),data_format='channels_first'),
MaxPooling2D((3,3), data_format='channels_first')
])
print(model.summary())
Run Code Online (Sandbox Code Playgroud)
模型的总结是
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_2 (Conv2D) (None, 16, 28, 28) 160
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 16, 9, 9) 0
=================================================================
Total params: 160
Trainable params: 160
Non-trainable params: 0
_________________________________________________________________
None
Run Code Online (Sandbox Code Playgroud)
和编译为
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_2 (Conv2D) (None, 16, 28, …Run Code Online (Sandbox Code Playgroud) 我使用 Matplotlib 和 Seaborn 来进行一些绘图。我想要具有透明背景而不是黑色背景的绘图。我的代码是
plt.style.use("dark_background")
plt.figure(figsize=(15,8))
sns.swarmplot(x='type',y='value', data=df, size=3.5, color='r', alpha=0.4)
sns.boxplot(x='type',y='value',data=df)
Run Code Online (Sandbox Code Playgroud)
现在有没有任何样式或技术可以使用我的单元格具有相同的绘图背景颜色,即我的绘图背景是透明的。
谢谢
我最近遇到一件事,让我注意到numpy.var()和pandas.DataFrame.var()orpandas.Series.var()给出了不同的值。我想知道它们之间有什么区别吗?
这是我的数据集。
Country GDP Area Continent
0 India 2.79 3.287 Asia
1 USA 20.54 9.840 North America
2 China 13.61 9.590 Asia
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
catDf.iloc[:,1:-1] = ss.fit_transform(catDf.iloc[:,1:-1])
Run Code Online (Sandbox Code Playgroud)
现在检查 Pandas 方差
# Pandas Variance
print(catDf.var())
print(catDf.iloc[:,1:-1].var())
print(catDf.iloc[:,1].var())
print(catDf.iloc[:,2].var())
Run Code Online (Sandbox Code Playgroud)
输出是
GDP 1.5
Area 1.5
dtype: float64
GDP 1.5
Area 1.5
dtype: float64
1.5000000000000002
1.5000000000000002
Run Code Online (Sandbox Code Playgroud)
而它应该是 1,因为我已经使用了 StandardScaler。
对于 numpy 方差
print(catDf.iloc[:,1:-1].values.var())
print(catDf.iloc[:,1].values.var())
print(catDf.iloc[:,2].values.var())
Run Code Online (Sandbox Code Playgroud)
输出是
1.0000000000000002
1.0000000000000002
1.0000000000000002
Run Code Online (Sandbox Code Playgroud)
这似乎是正确的。
我正在使用 Paddle OCR,我想知道 bbx off paddle OCR 的输出格式是什么。我在Paddle的github上找不到。这是我的代码。
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(use_angle_cls=False, lang='en', rec=False) # need to run only once to download and load model into memory
result = ocr.ocr(img, cls=False)
Run Code Online (Sandbox Code Playgroud)
输出
[[[[8.0, 12.0], [89.0, 12.0], [89.0, 25.0], [8.0, 25.0]],
('@kheengz_yfk', 0.9460259079933167)],
[[[6.0, 31.0], [227.0, 29.0], [227.0, 44.0], [6.0, 46.0]],
('EBIT is a week old today. and', 0.847086489200592)],
[[[4.0, 47.0], [225.0, 49.0], [225.0, 64.0], [4.0, 62.0]],
('the homebors came together...Seemore', 0.942597508430481)],
[[[7.0, 70.0], [183.0, 70.0], [183.0, 83.0], …Run Code Online (Sandbox Code Playgroud) 假设我有一个链表类,如下所示。
struct Node {
int data;
Node* rptr;
};
class LinkedList
{
public:
Node* curr;
Node* prev;
Node* first;
Node node;
LinkedList()
{
curr = NULL;
prev = NULL;
first = NULL;
node.data = NAN;
node.rptr = NULL;
}
void push(int);
void pop();
};
void LinkedList::push(int data)
{
curr = new Node;
curr->data = data;
curr->rptr = NULL;
if (first == NULL)
{
prev = first = curr;
}
else
{
prev->rptr = curr;
curr->data = data;
prev = curr; …Run Code Online (Sandbox Code Playgroud) 我有一个格式为的列表
[[0,0], [1,0], [1,1], [0,1], [0,0]]
现在我想将其转换为格式"((0 0,1 0,1 1,0 1,0 0))"
我尝试了一些解决方案,但它不起作用,即
def conv(l):
return str(map(lambda a: " ".join(a), l))
Run Code Online (Sandbox Code Playgroud)
我的子列表将始终有 2 个点,即 x,y,主列表可以有很多点,即 [[x,y],[x,y],......]
python ×7
matplotlib ×2
pandas ×2
c++ ×1
fastapi ×1
java ×1
keras ×1
linked-list ×1
netbeans-11 ×1
numpy ×1
paddleocr ×1
pointers ×1
scikit-learn ×1
seaborn ×1
statistics ×1
tensorflow ×1