import requests
def fetch_lms_data(api_url, token):
headers = {'Authorization': f'Bearer {token}'}
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
return response.json()
else:
return None
# 示例调用
api_url = "https://example.edu/api/student_activity"
token = "your_token_here"
data = fetch_lms_data(api_url, token)
if data:
print("数据成功获取!")
else:
print("数据获取失败,请检查API连接。")
]]>
import pandas as pd
def clean_data(raw_data):
df = pd.DataFrame(raw_data)
# 删除缺失值
df.dropna(inplace=True)
# 转换日期格式
df['timestamp'] = pd.to_datetime(df['timestamp'])
return df
cleaned_df = clean_data(data)
print(cleaned_df.head())
]]>
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
X = cleaned_df[['attendance', 'homework_completion']]
y = cleaned_df['performance']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = LogisticRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(predictions)
]]>
import matplotlib.pyplot as plt
import seaborn as sns
sns.barplot(x='attendance', y='performance', data=cleaned_df)
plt.title('Attendance vs Performance')
plt.show()
]]>