当前位置: 首页 > news >正文

基于autokeras的简单天气预报例子和运行输出

import numpy as np  
from autokeras import StructuredDataClassifier  
from sklearn.model_selection import train_test_split  
from sklearn.preprocessing import StandardScaler  
  
# 模拟数据  
np.random.seed(0)  
n_samples = 1000  
X = np.random.rand(n_samples, 3)  # 假设有三个特征:温度、湿度、气压  
y = (X[:, 0] * 0.5 + X[:, 1] * 0.3 + np.random.randn(n_samples) * 0.1 > 0.5).astype(int)  # 简单的逻辑来模拟是否下雨  
  
# 数据预处理  
scaler = StandardScaler()  
X_scaled = scaler.fit_transform(X)  
  
# 划分数据集  
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)  
  
# 初始化并训练模型  
clf = StructuredDataClassifier(overwrite=True, max_trials=1)  # 设置max_trials限制搜索次数  
clf.fit(X_train, y_train, epochs=10)  # epochs控制训练时间  
  
# 评估模型  
print('Test accuracy:', clf.evaluate(X_test, y_test))  
  

test@ubuntu:~/python$ python3 test-ak-weather.py 
Using TensorFlow backend
2024-09-24 20:45:27.725676: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2024-09-24 20:45:27.803135: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2024-09-24 20:45:27.803943: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-09-24 20:45:28.765172: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT

Search: Running Trial #1

Value             |Best Value So Far |Hyperparameter
True              |True              |structured_data_block_1/normalize
2                 |2                 |structured_data_block_1/dense_block_1/num_layers
False             |False             |structured_data_block_1/dense_block_1/use_batchnorm
0                 |0                 |structured_data_block_1/dense_block_1/dropout
32                |32                |structured_data_block_1/dense_block_1/units_0
32                |32                |structured_data_block_1/dense_block_1/units_1
0                 |0                 |classification_head_1/dropout
adam              |adam              |optimizer
0.001             |0.001             |learning_rate

Epoch 1/10
20/20 [==============================] - 1s 17ms/step - loss: 0.6362 - accuracy: 0.6875 - val_loss: 0.5740 - val_accuracy: 0.7937
Epoch 2/10
20/20 [==============================] - 0s 7ms/step - loss: 0.5203 - accuracy: 0.8281 - val_loss: 0.4791 - val_accuracy: 0.8375
Epoch 3/10
20/20 [==============================] - 0s 7ms/step - loss: 0.4325 - accuracy: 0.8609 - val_loss: 0.4038 - val_accuracy: 0.8562
Epoch 4/10
20/20 [==============================] - 0s 7ms/step - loss: 0.3708 - accuracy: 0.8625 - val_loss: 0.3559 - val_accuracy: 0.8750
Epoch 5/10
20/20 [==============================] - 0s 7ms/step - loss: 0.3361 - accuracy: 0.8562 - val_loss: 0.3321 - val_accuracy: 0.8875
Epoch 6/10
20/20 [==============================] - 0s 6ms/step - loss: 0.3198 - accuracy: 0.8562 - val_loss: 0.3216 - val_accuracy: 0.8875
Epoch 7/10
20/20 [==============================] - 0s 6ms/step - loss: 0.3121 - accuracy: 0.8578 - val_loss: 0.3167 - val_accuracy: 0.8875
Epoch 8/10
20/20 [==============================] - 0s 6ms/step - loss: 0.3077 - accuracy: 0.8578 - val_loss: 0.3140 - val_accuracy: 0.8813
Epoch 9/10
20/20 [==============================] - 0s 6ms/step - loss: 0.3046 - accuracy: 0.8594 - val_loss: 0.3125 - val_accuracy: 0.8813
Epoch 10/10
20/20 [==============================] - 0s 6ms/step - loss: 0.3023 - accuracy: 0.8594 - val_loss: 0.3117 - val_accuracy: 0.8813

Trial 1 Complete [00h 00m 04s]
val_accuracy: 0.887499988079071

Best val_accuracy So Far: 0.887499988079071
Total elapsed time: 00h 00m 04s
Epoch 1/10
25/25 [==============================] - 1s 3ms/step - loss: 0.5459 - accuracy: 0.7638
Epoch 2/10
25/25 [==============================] - 0s 3ms/step - loss: 0.4548 - accuracy: 0.8138
Epoch 3/10
25/25 [==============================] - 0s 4ms/step - loss: 0.3885 - accuracy: 0.8525
Epoch 4/10
25/25 [==============================] - 0s 3ms/step - loss: 0.3459 - accuracy: 0.8587
Epoch 5/10
25/25 [==============================] - 0s 3ms/step - loss: 0.3237 - accuracy: 0.8600
Epoch 6/10
25/25 [==============================] - 0s 3ms/step - loss: 0.3135 - accuracy: 0.8587
Epoch 7/10
25/25 [==============================] - 0s 3ms/step - loss: 0.3081 - accuracy: 0.8600
Epoch 8/10
25/25 [==============================] - 0s 4ms/step - loss: 0.3048 - accuracy: 0.8625
Epoch 9/10
25/25 [==============================] - 0s 3ms/step - loss: 0.3024 - accuracy: 0.8612
Epoch 10/10
25/25 [==============================] - 0s 4ms/step - loss: 0.3005 - accuracy: 0.8637
7/7 [==============================] - 0s 2ms/step - loss: 0.2812 - accuracy: 0.8900
Test accuracy: [0.28117990493774414, 0.8899999856948853]
/home/test/.local/lib/python3.8/site-packages/keras/src/engine/training.py:3000: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.
  saving_api.save_model(
Model saved successfully.
 

相关文章:

  • wordpress自动挣钱天津优化代理
  • 男女做爰全过程网站合肥全网优化
  • 合伙建网站武汉推广系统
  • 顺德品牌网站怎么做网络推广
  • 网站建设环境配置seo学校培训课程
  • 论文引用网站数据 如何做注释seo管理系统
  • Maven 基础知识
  • HarmonyOS-ArkUI 装饰器V2 @ObservedV2与@Trace装饰器
  • 3ds Max 2016的版本怎么处理 按键输入被主程序截断 C#winform窗体接受不到英文输入
  • linux入门六:Linux Shell 编程
  • c++的函数重载
  • 机器学习 | 强化学习方法分类汇总 | 概念向
  • 国产信创数据库:PolarDB 分布式版 V2.0,支持集中分布式一体化
  • Vanna + qwq32b 实现 text2SQL
  • springboot集成springcloud vault读值示例
  • C++ - 数据容器之 unordered_map(声明与初始化、插入元素、访问元素、遍历元素、删除元素、查找元素)
  • 三相电为什么没零线也能通电
  • kali linux vmware 光标无法移出vmware,需要按ctrl + alt 才能移出光标
  • 【DB2】事务日志满/归档占用较大问题处理记录
  • 深入解析栈式虚拟机与反向波兰表示法
  • FacialExpressionDetection的conda虚拟环境搭建Window
  • 清华DeepSeek教程又双叒叕更新了!(共7份PDF下载)
  • DAPP实战篇:使用web3.js实现前端输入钱包地址查询该地址的USDT余额——前端篇
  • 算法竞赛中常用的数据处理库函数
  • 2025常用的ETL 产品推荐:助力企业激活数据价值
  • PyTorch Tensor维度变换实战:view/squeeze/expand/repeat全解析