-
Notifications
You must be signed in to change notification settings - Fork 1
Chương 2_Bài tập số 5_Dùng PythonAI viết code dự đoán Số học và Data Visual giải Bingo18 trong Lý thuyết trò chơi
PhD Le Toan Thang edited this page Apr 11, 2024
·
4 revisions
Bài tập 5: Dùng PythonAI viết code dự đoán Số học và Data Visual giải Bingo18 trong Lý thuyết trò chơi
https://vietlott.vn/vi/trung-thuong/ket-qua-trung-thuong/winning-number-bingo18
Sau khi copy/paste các dữ liệu vào Excel, CSV hoặc MS-SQL db
0 3;6;2
1 5;6;4
2 6;1;5
3 2;5;4
4 1;3;4
5 1;3;2
6 5;4;3
7 1;3;3
8 1;5;5
9 1;6;5
10 5;2;2
11 6;1;1
12 5;6;1
13 1;4;6
14 2;1;6
15 2;6;6
16 6;4;4
17 5;4;2
18 3;3;2
19 3;3;2
20 1;5;1
21 6;1;1
22 6;1;3
23 1;4;4
24 6;2;2
25 3;6;2
26 4;4;1
27 2;1;6
28 3;6;2
29 3;5;5
30 1;4;2
31 1;1;2
32 5;5;1
33 2;1;1
34 5;5;5
35 2;4;6
36 1;4;2
37 6;1;6
38 4;4;1
39 5;1;2
40 6;1;3
41 6;3;4
42 6;3;1
43 6;4;5
44 4;2;2
45 5;3;6
46 6;4;3
47 1;6;4
48 4;2;4
49 2;2;4
50 1;1;2
51 4;6;1
52 5;1;2
53 4;1;6
54 5;3;1
55 2;6;4
56 6;1;2
57 6;4;6
58 6;1;2
59 4;4;1
60 2;4;3
61 5;1;3
62 3;1;2
63 2;5;6
64 6;2;3
65 4;1;6
66 5;3;1
67 2;6;4
68 6;1;2
69 6;4;6
70 6;1;2
71 4;4;1
72 2;4;3
73 5;1;3
74 3;1;2
75 2;5;6
76 6;2;3
77 5;2;2
78 4;2;1
79 6;5;6
80 2;2;6
81 5;1;6
82 2;5;6
83 1;6;3
84 4;1;3
85 1;3;6
86 4;6;1
87 6;2;2
88 5;5;4
89 1;3;6
90 6;2;6
91 1;2;6
92 4;3;4
93 2;6;5
94 2;4;4
Các hàm pd.read_csv
import numpy as np
import pandas as pd
#pd.__version__
import seaborn as sns
from matplotlib import pyplot as plt
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
from sklearn.linear_model import LinearRegression
import warnings
warnings.filterwarnings('ignore')
df = pd.read_csv(r"C:\Python311\workspaces\bingo18.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
pd.set_option("display.max_columns",60)
df.shape
df
# Import necessary libraries
import numpy as np
import tensorflow as tf
from tensorflow import keras
from keras import layers
from art import text2art
# Function to print the introduction of the program
def print_intro():
# Generate ASCII art with the text "LotteryAi"
ascii_art = text2art("Binggo 18 ball")
# Print the introduction and ASCII art
print("============================================================")
print("Source code Python AI: Le Toan Thang")
print("BTC: from poe.com>PythonChatAI")
print("ETH & BNB: Github.com/PhDLeToanThang/")
print("============================================================")
print(ascii_art)
print("Lottery prediction artificial intelligence")
# Function to load data from a file and preprocess it
def load_data():
# Load data from file, ignoring white spaces and accepting unlimited length numbers
data = np.genfromtxt('bingo18b.csv', delimiter=';', dtype=int)
# Replace all -1 values with 0
data[data == -1] = 0
# Split data into training and validation sets
train_data = data[:int(0.8*len(data))]
val_data = data[int(0.8*len(data)):]
# Get the maximum value in the data
max_value = np.max(data)
return train_data, val_data, max_value
# Function to create the model
def create_model(num_features, max_value):
# Create a sequential model
model = keras.Sequential()
# Add an Embedding layer, LSTM layer, and Dense layer to the model
model.add(layers.Embedding(input_dim=max_value+1, output_dim=64))
model.add(layers.LSTM(256))
model.add(layers.Dense(num_features, activation='softmax'))
# Compile the model with categorical crossentropy loss, adam optimizer, and accuracy metric
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
# Function to train the model
def train_model(model, train_data, val_data):
# Fit the model on the training data and validate on the validation data for 100 epochs
history = model.fit(train_data, train_data, validation_data=(val_data, val_data), epochs=100)
# Function to predict numbers using the trained model
def predict_numbers(model, val_data, num_features):
# Predict on the validation data using the model
predictions = model.predict(val_data)
# Get the indices of the top 'num_features' predictions for each sample in validation data
indices = np.argsort(predictions, axis=1)[:, -num_features:]
# Get the predicted numbers using these indices from validation data
predicted_numbers = np.take_along_axis(val_data, indices, axis=1)
return predicted_numbers
# Function to print the predicted numbers
def print_predicted_numbers(predicted_numbers):
# Print a separator line and "Predicted Numbers:"
print("============================================================")
print("Predicted Numbers:")
# Print only the first row of predicted numbers
print(', '.join(map(str, predicted_numbers[0])))
# Main function to run everything
def main():
# Print introduction of program
print_intro()
# Load and preprocess data
train_data, val_data, max_value = load_data()
# Get number of features from training data
num_features = train_data.shape[1]
# Create and compile model
model = create_model(num_features, max_value)
# Train model
train_model(model, train_data, val_data)
# Predict numbers using trained model
predicted_numbers = predict_numbers(model, val_data, num_features)
# Print predicted numbers
print_predicted_numbers(predicted_numbers)
# Run main function if this script is run directly (not imported as a module)
if __name__ == "__main__":
main()
Màn kết quả:
============================================================ Predicted Numbers: 5, 6, 2
- Tiếp theo đặt cược hoặc theo dõi kết quả : Nhỏ, Hòa, Lớn
- Business Analyst (BA) là một nghề tồn tại từ lâu trên toàn cầu, nhưng ở Việt Nam thì vẫn còn khá mới (xuất hiện khoảng hơn 27 năm).
- Tôi thực sự đánh giá cao nghề này và trong quá trình làm việc, tôi đã gặp phải nhiều thách thức, từ đó tôi đã hiểu rõ những điểm mạnh và điểm yếu của bản thân. Tôi nhận thấy rằng trong lĩnh vực này có nhiều vấn đề phức tạp và khó khăn, nhưng khi chúng được giải quyết, thì cảm giác thật tuyệt vời.
- BA xuất hiện với mục tiêu giải quyết vấn đề. Đó có thể là biến một điều không tốt thành điều tốt hơn, hoặc cải thiện những điều đã tốt để trở nên tốt hơn. Việc mang lại ý nghĩa cho người khác thực sự là một điều mà tôi khó lòng tranh cãi hay bỏ qua.