tf.is_finite(x, name=None)

本文介绍TensorFlow中tf.is_finite函数的使用方法及参数含义,该函数用于判断张量中的元素是否为有限数值。通过示例演示如何使用此函数,并展示其返回布尔类型张量的特点。
部署运行你感兴趣的模型镜像


tf.is_finite(x, name=None)
Returns which elements of x are finite.


Args:
x: A Tensor. Must be one of the following types: float32, float64.
name: A name for the operation (optional).

Returns:A Tensor of type bool.

代码示例:

a = tf.random_uniform([2,3], minval = 10, maxval = 11 , dtype=tf.float32)
sess.run(tf.is_finite(a))

输出:

array([[ True,  True,  True],
       [ True,  True,  True]], dtype=bool)

即tf.is_finite是判定tensor里面的值是不是有限数,是的话则返回true,否则返回false

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.15

TensorFlow-v2.15

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

# -*- coding: utf-8 -*- """ DKT-DSC for Assistment2012 (优化版) - 修复数据泄露问题 最后更新: 2024-07-01 """ import os import sys import numpy as np import tensorflow.compat.v1 as tf os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"] = "0" config = tf.ConfigProto() config.gpu_options.allow_growth = True tf.disable_v2_behavior() # 安全导入psutil模块 try: import psutil HAS_PSUTIL = True except ImportError: HAS_PSUTIL = False print("警告: psutil模块未安装,内存监控功能受限") from scipy.sparse import coo_matrix from tensorflow.contrib import rnn import pandas as pd from tqdm import tqdm from sklearn.metrics import mean_squared_error, r2_score, roc_curve, auc import math import random # ==================== 配置部分 ==================== # 使用实际数据路径 DATA_BASE_PATH = '/home/yhh/students/jianglu/DKT2/DKT/data/' data_name = 'Assist_2012' # 修正数据集名称 KNOWLEDGE_GRAPH_PATHS = { 'graphml': './output_assist2012_gat_improved/knowledge_graph.graphml', 'nodes': './output_assist2012_gat_improved/graph_nodes.csv', 'edges': './output_assist2012_gat_improved/graph_edges.csv' } # ==================== Flags配置 ==================== tf.flags.DEFINE_float("epsilon", 1e-8, "Adam优化器的epsilon值") tf.flags.DEFINE_float("l2_lambda", 0.005, "L2正则化系数") # 减小正则化强度 tf.flags.DEFINE_float("learning_rate", 1e-4, "学习率") tf.flags.DEFINE_float("max_grad_norm", 3.0, "梯度裁剪阈值") # 更严格的梯度裁剪 tf.flags.DEFINE_float("keep_prob", 0.8, "Dropout保留概率") # 减小dropout tf.flags.DEFINE_integer("hidden_layer_num", 1, "隐藏层数量") tf.flags.DEFINE_integer("hidden_size", 48, "隐藏层大小") # 增加隐藏层大小 tf.flags.DEFINE_integer("evaluation_interval", 2, "评估间隔周期数") tf.flags.DEFINE_integer("batch_size", 128, "批次大小") tf.flags.DEFINE_integer("problem_len", 15, "问题序列长度") # 增加序列长度 tf.flags.DEFINE_integer("epochs", 100, "训练周期数") tf.flags.DEFINE_boolean("allow_soft_placement", True, "允许软设备放置") tf.flags.DEFINE_boolean("log_device_placement", False, "记录设备放置信息") tf.flags.DEFINE_string("train_data_path", f'{DATA_BASE_PATH}{data_name}_train.csv', "训练数据路径") tf.flags.DEFINE_string("test_data_path", f'{DATA_BASE_PATH}{data_name}_test.csv', "测试数据路径") FLAGS = tf.flags.FLAGS # 焦点损失参数 FOCAL_LOSS_GAMMA = 1.5 # 调整焦点损失参数 FOCAL_LOSS_ALPHA = 0.3 # 学习率衰减参数 DECAY_STEPS = 2000 DECAY_RATE = 0.95 # 学习率预热步数 WARMUP_STEPS = 2000 # 内存监控函数 def memory_usage(): """增强的内存监控函数,处理psutil缺失情况""" if HAS_PSUTIL: try: process = psutil.Process(os.getpid()) return process.memory_info().rss / (1024 ** 2) except: return 0.0 return 0.0 # ==================== 知识图谱加载器 ==================== class KnowledgeGraphLoader: def __init__(self): self.node_features = None self.adj_matrix = None self.problem_to_node = {} self.node_id_map = {} self.static_node_count = 0 self._rows = None self._cols = None def load(self): """加载知识图谱数据并进行严格的数据验证""" print("\n[KG] 加载知识图谱...") try: if not os.path.exists(KNOWLEDGE_GRAPH_PATHS['nodes']): raise FileNotFoundError(f"节点文件未找到: {KNOWLEDGE_GRAPH_PATHS['nodes']}") if not os.path.exists(KNOWLEDGE_GRAPH_PATHS['edges']): raise FileNotFoundError(f"边文件未找到: {KNOWLEDGE_GRAPH_PATHS['edges']}") node_df = pd.read_csv(KNOWLEDGE_GRAPH_PATHS['nodes']) self.static_node_count = len(node_df) print(f"[KG] 总节点数: {self.static_node_count}") # 处理空值 - 根据验证报告中的发现 print("[KG] 处理特征空值...") feature_cols = [col for col in node_df.columns if col not in ['node_id', 'type']] # 特别处理total_attempts特征 if 'total_attempts' in feature_cols: # 概念节点使用概念节点中位数填充 concept_mask = node_df['type'] == 'concept' concept_median = node_df.loc[concept_mask, 'total_attempts'].median() # 处理NaN值 if pd.isna(concept_median): concept_median = 0.0 node_df.loc[concept_mask, 'total_attempts'] = node_df.loc[concept_mask, 'total_attempts'].fillna(concept_median) # 问题节点使用问题节点中位数填充 problem_mask = node_df['type'] == 'problem' problem_median = node_df.loc[problem_mask, 'total_attempts'].median() # 处理NaN值 if pd.isna(problem_median): problem_median = 0.0 node_df.loc[problem_mask, 'total_attempts'] = node_df.loc[problem_mask, 'total_attempts'].fillna(problem_median) print(f" 填充 total_attempts 缺失值: 概念节点={concept_median}, 问题节点={problem_median}") # 处理其他数值特征 other_cols = [col for col in feature_cols if col != 'total_attempts'] for col in other_cols: # 分类型填充 if 'confidence' in col or 'affect' in col: # 情感特征使用全局平均值填充 global_mean = node_df[col].mean() # 处理NaN值 if pd.isna(global_mean): global_mean = 0.0 node_df[col] = node_df[col].fillna(global_mean) print(f" 填充 {col} 缺失值: 全局均值={global_mean:.4f}") else: # 其他特征按问题类型分组填充 problem_mask = node_df['type'] == 'problem' problem_mean = node_df.loc[problem_mask, col].mean() # 处理NaN值 if pd.isna(problem_mean): problem_mean = 0.0 node_df.loc[problem_mask, col] = node_df.loc[problem_mask, col].fillna(problem_mean) concept_mask = node_df['type'] == 'concept' concept_mean = node_df.loc[concept_mask, col].mean() # 处理NaN值 if pd.isna(concept_mean): concept_mean = 0.0 node_df.loc[concept_mask, col] = node_df.loc[concept_mask, col].fillna(concept_mean) print(f" 填充 {col} 缺失值: 问题节点={problem_mean:.4f}, 概念节点={concept_mean:.4f}") print("\n[KG诊断] 特征分析...") if feature_cols: raw_features = node_df[feature_cols].values nan_count = np.isnan(raw_features).sum() inf_count = np.isinf(raw_features).sum() print(f" 总特征值数: {raw_features.size}") print(f" NaN特征数: {nan_count}") print(f" Inf特征数: {inf_count}") if nan_count > 0 or inf_count > 0: print(f"⚠️ 警告: 节点特征包含 {nan_count} 个NaN和 {inf_count} 个Inf值,将被替换为0") raw_features = np.nan_to_num(raw_features) # 标准化特征并确保为float32类型 feature_mean = np.mean(raw_features, axis=0) feature_std = np.std(raw_features, axis=0) + 1e-8 self.node_features = np.array( (raw_features - feature_mean) / feature_std, dtype=np.float32 # 显式指定为float32 ) self.node_features = np.nan_to_num(self.node_features) # 再次确保无NaN else: print("警告: 节点文件中没有特征列") self.node_features = np.zeros((self.static_node_count, 1), dtype=np.float32) # 创建节点ID映射 self.node_id_map = {} for idx, row in node_df.iterrows(): self.node_id_map[row['node_id']] = idx # 创建问题ID到节点索引的映射 self.problem_to_node = {} problem_count = 0 for idx, row in node_df.iterrows(): if row['type'] == 'problem': try: parts = row['node_id'].split('_') if len(parts) < 2: continue problem_id = int(parts[1]) self.problem_to_node[problem_id] = idx problem_count += 1 except: continue print(f"[KG] 已加载 {problem_count} 个问题节点映射") # 加载边数据并进行优化 edge_df = pd.read_csv(KNOWLEDGE_GRAPH_PATHS['edges']) print("[KG] 优化邻接矩阵(保留每个节点的前100个邻居)...") rows, cols, data = [], [], [] valid_edge_count = 0 invalid_edge_count = 0 # 限制每个节点的邻居数量以提高效率 grouped = edge_df.groupby('source') for src, group in tqdm(grouped, total=len(grouped), desc="处理边数据"): src_idx = self.node_id_map.get(src, -1) if src_idx == -1: invalid_edge_count += len(group) continue neighbors = [] for _, row in group.iterrows(): tgt_idx = self.node_id_map.get(row['target'], -1) if tgt_idx != -1: neighbors.append((tgt_idx, row['weight'])) # 根据权重排序并取Top 100 neighbors.sort(key=lambda x: x[1], reverse=True) top_k = min(100, len(neighbors)) # 限制邻居数量 for i in range(top_k): tgt_idx, weight = neighbors[i] rows.append(src_idx) cols.append(tgt_idx) data.append(weight) valid_edge_count += 1 # 添加自环 for i in range(self.static_node_count): rows.append(i) cols.append(i) data.append(1.0) valid_edge_count += 1 # 创建稀疏邻接矩阵 adj_coo = coo_matrix( (data, (rows, cols)), shape=(self.static_node_count, self.static_node_count), dtype=np.float32 ) self.adj_matrix = adj_coo.tocsc() self._rows = np.array(rows) self._cols = np.array(cols) print(f"[KG] 邻接矩阵构建完成 | 节点: {self.static_node_count} | 边: {len(data)}") print(f"[KG优化] 最大行索引: {np.max(self._rows)} | 最大列索引: {np.max(self._cols)}") except Exception as e: import traceback print(f"知识图谱加载失败: {str(e)}") traceback.print_exc() raise RuntimeError(f"知识图谱加载失败: {str(e)}") from e # ==================== 图注意力层 ==================== class GraphAttentionLayer: def __init__(self, input_dim, output_dim, kg_loader, scope=None): self.kg_loader = kg_loader self.node_count = kg_loader.static_node_count self._rows = kg_loader._rows self._cols = kg_loader._cols with tf.variable_scope(scope or "GAT"): self.W = tf.get_variable( "W", [input_dim, output_dim], initializer=tf.initializers.variance_scaling( scale=0.1, mode='fan_avg', distribution='uniform') ) self.attn_kernel = tf.get_variable( "attn_kernel", [output_dim * 2, 1], initializer=tf.initializers.variance_scaling( scale=0.1, mode='fan_avg', distribution='uniform') ) self.bias = tf.get_variable( "bias", [output_dim], initializer=tf.zeros_initializer() ) def __call__(self, inputs): inputs = tf.clip_by_value(inputs, -5, 5) inputs = tf.check_numerics(inputs, "GAT输入包含NaN或Inf") # 特征变换 h = tf.matmul(inputs, self.W) h = tf.clip_by_value(h, -5, 5) h = tf.check_numerics(h, "特征变换后包含NaN或Inf") # 注意力机制 h_src = tf.gather(h, self._rows) h_dst = tf.gather(h, self._cols) h_concat = tf.concat([h_src, h_dst], axis=1) edge_logits = tf.squeeze(tf.matmul(h_concat, self.attn_kernel), axis=1) edge_logits = tf.clip_by_value(edge_logits, -10, 10) edge_attn = tf.nn.leaky_relu(edge_logits, alpha=0.2) # 创建稀疏注意力矩阵 edge_indices = tf.constant(np.column_stack((self._rows, self._cols)), dtype=tf.int64) sparse_attn = tf.SparseTensor( indices=edge_indices, values=edge_attn, dense_shape=[self.node_count, self.node_count] ) # 稀疏softmax和矩阵乘法 sparse_attn_weights = tf.sparse_softmax(sparse_attn) output = tf.sparse_tensor_dense_matmul(sparse_attn_weights, h) output = tf.clip_by_value(output, -5, 5) output += self.bias output = tf.nn.elu(output) output = tf.check_numerics(output, "最终GAT输出包含NaN或Inf") return output # ==================== 学生知识追踪模型 ==================== class StudentModel: def __init__(self, is_training, config): self.batch_size = config.batch_size self.num_skills = config.num_skills self.num_steps = config.num_steps self.current = tf.placeholder(tf.int32, [None, self.num_steps], name='current') self.next = tf.placeholder(tf.int32, [None, self.num_steps], name='next') self.target_id = tf.placeholder(tf.int32, [None], name='target_ids') self.target_correctness = tf.placeholder(tf.float32, [None], name='target_correctness') with tf.device('/gpu:0'), tf.variable_scope("KnowledgeGraph", reuse=tf.AUTO_REUSE): # 加载知识图谱 kg_loader = KnowledgeGraphLoader() kg_loader.load() kg_node_features = tf.constant(kg_loader.node_features, dtype=tf.float32) kg_node_features = tf.check_numerics(kg_node_features, "知识图谱节点特征包含NaN或Inf") # 精简GAT层 - 减少层数和维度 gat_output = kg_node_features for i in range(2): # 减少GAT层数为2 with tf.variable_scope(f"GAT_Layer_{i + 1}"): gat_layer = GraphAttentionLayer( input_dim=gat_output.shape[1] if i > 0 else kg_node_features.shape[1], output_dim=24 if i == 0 else 16, # 减少输出维度 kg_loader=kg_loader ) gat_output = gat_layer(gat_output) gat_output = tf.nn.elu(gat_output) self.skill_embeddings = gat_output with tf.variable_scope("FeatureProcessing"): batch_size = tf.shape(self.next)[0] # 动态获取批次大小 # 当前问题嵌入 current_indices = tf.minimum(self.current, kg_loader.static_node_count - 1) current_embed = tf.nn.embedding_lookup(self.skill_embeddings, current_indices) # 构建输入序列 - 移除下一问题嵌入(修复数据泄露) inputs = [] # 使用当前问题作为有效掩码(而不是下一个问题) valid_mask = tf.cast(tf.not_equal(self.current, 0), tf.float32) answers_float = tf.cast(self.next, tf.float32) # 历史表现特征 - 修复符号张量问题 zero_vector = tf.zeros([1, 1], dtype=tf.float32) history = tf.tile(zero_vector, [batch_size, 1]) elapsed_time = tf.tile(zero_vector, [batch_size, 1]) # 循环处理每个时间步 for t in range(self.num_steps): # 创建时间相关的特征 if t > 0: # 计算历史表现(只使用t-1及之前的信息) past_answers = answers_float[:, :t] # 只使用当前时间步之前的信息 past_valid_mask = valid_mask[:, :t] correct_count = tf.reduce_sum(past_answers * past_valid_mask, axis=1, keepdims=True) total_valid = tf.reduce_sum(past_valid_mask, axis=1, keepdims=True) history = correct_count / (total_valid + 1e-8) # 计算经过的时间 elapsed_time = tf.fill([batch_size, 1], tf.cast(t, tf.float32)) # 难度特征 - 使用知识图谱中的准确率特征 # 确保只使用当前问题的特征 difficulty_feature = tf.gather( kg_loader.node_features[:, 0], # 假设第一个特征是准确率 tf.minimum(self.current[:, t], kg_loader.static_node_count - 1) ) difficulty_feature = tf.cast(difficulty_feature, tf.float32) # 情感特征 - 使用知识图谱中的情感特征 affect_features = [] for i in range(1, 5): # 使用前4个情感特征 affect_feature = tf.gather( kg_loader.node_features[:, i], tf.minimum(self.current[:, t], kg_loader.static_node_count - 1) ) affect_feature = tf.cast(affect_feature, tf.float32) affect_features.append(tf.reshape(affect_feature, [-1, 1])) # 组合所有特征 - 移除了下一问题嵌入(修复数据泄露) combined = tf.concat([ current_embed[:, t, :], history, elapsed_time, tf.reshape(difficulty_feature, [-1, 1]), *affect_features ], axis=1) inputs.append(combined) # RNN模型 with tf.variable_scope("RNN"): cell = rnn.LSTMCell( FLAGS.hidden_size, initializer=tf.initializers.glorot_uniform(), forget_bias=1.0 ) if is_training and FLAGS.keep_prob < 1.0: cell = rnn.DropoutWrapper(cell, output_keep_prob=FLAGS.keep_prob) outputs, _ = tf.nn.dynamic_rnn( cell, tf.stack(inputs, axis=1), dtype=tf.float32 ) output = tf.reshape(outputs, [-1, FLAGS.hidden_size]) # 输出层 with tf.variable_scope("Output"): hidden = tf.layers.dense( output, units=32, activation=tf.nn.relu, kernel_initializer=tf.initializers.glorot_uniform(), name="hidden_layer" ) logits = tf.layers.dense( hidden, units=1, kernel_initializer=tf.initializers.glorot_uniform(), name="output_layer" ) # 损失计算 self._all_logits = tf.clip_by_value(logits, -20, 20) selected_logits = tf.gather(tf.reshape(self._all_logits, [-1]), self.target_id) self.pred = tf.clip_by_value(tf.sigmoid(selected_logits), 1e-8, 1 - 1e-8) # 焦点损失 labels = tf.clip_by_value(self.target_correctness, 0.05, 0.95) pos_weight = tf.reduce_sum(1.0 - labels) / (tf.reduce_sum(labels) + 1e-8) bce_loss = tf.nn.weighted_cross_entropy_with_logits( targets=labels, logits=selected_logits, pos_weight=pos_weight ) loss = tf.reduce_mean(bce_loss) # L2正则化 l2_loss = tf.add_n([ tf.nn.l2_loss(v) for v in tf.trainable_variables() if 'bias' not in v.name ]) * FLAGS.l2_lambda self.cost = loss + l2_loss # ==================== 数据加载 ==================== def read_data_from_csv_file(path, kg_loader, is_training=False): """更鲁棒的数据加载函数""" students = [] student_ids = [] max_skill = 0 missing_problems = set() # 增强文件存在性检查 if not os.path.exists(path): print(f"❌ 严重错误: 数据文件不存在: {path}") print("请检查以下可能原因:") print("1. 文件路径是否正确") print("2. 文件名是否匹配") print("3. 文件权限是否足够") # 尝试列出目录内容以便调试 dir_path = os.path.dirname(path) print(f"目录内容: {os.listdir(dir_path) if os.path.exists(dir_path) else '目录不存在'}") return [], [], [], 0, 0, 0 try: # 打印正在加载的文件路径 print(f"[数据] 加载数据文件: {path}") # 读取数据集 - 增强CSV读取兼容性 try: data_df = pd.read_csv(path) except Exception as e: print(f"CSV读取失败: {str(e)}") print("尝试使用备用方法读取...") # 尝试不同编码 encodings = ['utf-8', 'latin1', 'iso-8859-1', 'cp1252'] for encoding in encodings: try: data_df = pd.read_csv(path, encoding=encoding) print(f"成功使用 {encoding} 编码读取文件") break except Exception as e: print(f"编码 {encoding} 尝试失败: {str(e)}") continue if 'data_df' not in locals(): print("所有编码尝试失败,无法读取文件") return [], [], [], 0, 0, 0 print(f"[数据] 加载完成 | 记录数: {len(data_df)}") # 检查必要的列是否存在 - 支持多种列名变体 # 可能的列名变体 possible_columns = { 'user_id': ['user_id', 'userid', 'student_id', 'studentid'], 'problem_id': ['problem_id', 'problemid', 'skill_id', 'skillid'], 'correct': ['correct', 'correctness', 'answer', 'accuracy'], 'start_time': ['start_time', 'timestamp', 'time', 'date'] } # 查找实际列名 actual_columns = {} for col_type, possible_names in possible_columns.items(): found = False for name in possible_names: if name in data_df.columns: actual_columns[col_type] = name found = True break if not found: print(f"❌ 错误: 找不到 {col_type} 列") print(f"数据列: {list(data_df.columns)}") return [], [], [], 0, 0, 0 # 重命名列为标准名称以便后续处理 data_df = data_df.rename(columns={ actual_columns['user_id']: 'user_id', actual_columns['problem_id']: 'problem_id', actual_columns['correct']: 'correct', actual_columns['start_time']: 'start_time' }) print(f"[数据] 使用列: user_id, problem_id, correct, start_time") # 按学生分组 grouped = data_df.groupby('user_id') print(f"[数据] 分组完成 | 学生数: {len(grouped)}") for user_id, group in tqdm(grouped, total=len(grouped), desc="处理学生数据"): # 按时间排序 group = group.sort_values('start_time') problems = group['problem_id'].values answers = group['correct'].values.astype(int) # 筛选有效数据 - 添加详细日志 valid_data = [] invalid_count = 0 for i, (p, a) in enumerate(zip(problems, answers)): # 检查问题是否在知识图谱中 if p in kg_loader.problem_to_node and a in (0, 1): # 额外检查:确保问题特征不包含学生作答信息 node_idx = kg_loader.problem_to_node[p] if 'accuracy' in kg_loader.node_features[node_idx]: # 如果特征中包含准确率,警告可能的数据泄露 print(f"警告: 问题 {p} 的特征包含准确率信息,可能导致数据泄露") valid_data.append((p, a)) else: invalid_count += 1 if p != 0 and p not in missing_problems: print(f"警告: 问题ID {p} 不在知识图谱中 (学生: {user_id}, 位置: {i})") missing_problems.add(p) if len(valid_data) < 2: print(f"跳过数据不足的学生 {user_id} (有效交互: {len(valid_data)}, 无效: {invalid_count})") continue # 分割序列 problems, answers = zip(*valid_data) n_split = (len(problems) + FLAGS.problem_len - 1) // FLAGS.problem_len for k in range(n_split): start = k * FLAGS.problem_len end = (k + 1) * FLAGS.problem_len seg_problems = list(problems[start:end]) seg_answers = list(answers[start:end]) # 填充短序列 if len(seg_problems) < FLAGS.problem_len: pad_len = FLAGS.problem_len - len(seg_problems) seg_problems += [0] * pad_len seg_answers += [0] * pad_len # 训练数据增强 if is_training: valid_indices = [i for i, p in enumerate(seg_problems) if p != 0] if len(valid_indices) > 1 and random.random() > 0.5: random.shuffle(valid_indices) seg_problems = [seg_problems[i] for i in valid_indices] + seg_problems[len(valid_indices):] seg_answers = [seg_answers[i] for i in valid_indices] + seg_answers[len(valid_indices):] # 映射问题ID到知识图谱节点 mapped_problems = [] for p in seg_problems: if p == 0: mapped_problems.append(0) elif p in kg_loader.problem_to_node: mapped_problems.append(kg_loader.problem_to_node[p]) else: mapped_problems.append(0) students.append(([user_id, k], mapped_problems, seg_answers)) max_skill = max(max_skill, max(mapped_problems)) student_ids.append(user_id) except Exception as e: print(f"数据加载失败: {str(e)}") import traceback traceback.print_exc() return [], [], [], 0, 0, 0 avg_length = sum(len(s[1]) for s in students) / len(students) if students else 0 print(f"[数据统计] 学生数: {len(student_ids)} | 序列数: {len(students)}") print(f" 最大技能ID: {max_skill} | 平均序列长度: {avg_length:.1f}") print(f" 缺失问题数: {len(missing_problems)}") return students, [], student_ids, max_skill, 0, 0 # ==================== 训练流程 ==================== def run_epoch(session, model, data, run_type, eval_op, global_step=None): preds = [] labels = [] total_loss = 0.0 step = 0 processed_count = 0 total_batches = max(1, len(data) // model.batch_size) with tqdm(total=total_batches, desc=f"{run_type} Epoch") as pbar: index = 0 while index < len(data): # 准备批次数据 current_batch = [] next_batch = [] target_ids = [] target_correctness = [] for i in range(model.batch_size): if index >= len(data): break stu_id, problems, answers = data[index] valid_length = sum(1 for p in problems if p != 0) if valid_length < 1: index += 1 continue current_batch.append(problems) next_batch.append(answers) last_step = valid_length - 1 target_ids.append(i * model.num_steps + last_step) target_correctness.append(answers[last_step]) index += 1 if len(current_batch) == 0: pbar.update(1) step += 1 continue # 创建feed_dict feed = { model.current: np.array(current_batch, dtype=np.int32), model.next: np.array(next_batch, dtype=np.int32), model.target_id: np.array(target_ids, dtype=np.int32), model.target_correctness: np.array(target_correctness, dtype=np.float32) } # 运行计算 try: results = session.run( [model.pred, model.cost, eval_op], feed_dict=feed ) pred, loss = results[:2] preds.extend(pred.tolist()) labels.extend(target_correctness) total_loss += loss * len(current_batch) processed_count += len(current_batch) pbar.set_postfix( loss=f"{loss:.4f}", mem=f"{memory_usage():.1f}MB" ) pbar.update(1) step += 1 except Exception as e: print(f"\n训练错误: {str(e)}") import traceback traceback.print_exc() break # 计算指标 if not labels or not preds: print(f"{run_type}周期: 无有效样本!") return float('nan'), 0.5, 0.0, 0.0 labels = np.array(labels, dtype=np.float32) preds = np.array(preds, dtype=np.float32) mask = np.isfinite(labels) & np.isfinite(preds) if not mask.any(): print(f"{run_type}周期: 所有样本包含无效值!") return float('nan'), 0.5, 0.0, 0.0 labels = labels[mask] preds = preds[mask] try: rmse = np.sqrt(mean_squared_error(labels, preds)) fpr, tpr, _ = roc_curve(labels, preds) auc_score = auc(fpr, tpr) r2 = r2_score(labels, preds) avg_loss = total_loss / processed_count if processed_count > 0 else 0.0 print(f"\n{run_type}周期总结:") print(f" 样本数: {len(labels)} | 正样本比例: {np.mean(labels > 0.5):.3f}") print(f" Loss: {avg_loss:.4f} | RMSE: {rmse:.4f} | AUC: {auc_score:.4f} | R²: {r2:.4f}") # 添加预测值分布分析 print("\n预测值分布分析:") print(f" 最小值: {np.min(preds):.4f} | 最大值: {np.max(preds):.4f}") print(f" 均值: {np.mean(preds):.4f} | 中位数: {np.median(preds):.4f}") print(f" 标准差: {np.std(preds):.4f}") # 检查完美预测的情况 perfect_preds = np.sum((preds < 1e-5) | (preds > 1 - 1e-5)) if perfect_preds > 0: perfect_ratio = perfect_preds / len(preds) print(f" 警告: {perfect_preds}个样本({perfect_ratio*100:.2f}%)预测值为0或1") # 检查预测值是否全部相同 if np.all(preds == preds[0]): print(f" 严重警告: 所有预测值相同 ({preds[0]:.4f})") return rmse, auc_score, r2, avg_loss except Exception as e: print(f"指标计算错误: {str(e)}") return float('nan'), 0.5, 0.0, 0.0 # ==================== 主函数 ==================== def main(_): print(f"[系统] 训练数据路径: {FLAGS.train_data_path}") print(f"[系统] 测试数据路径: {FLAGS.test_data_path}") # 检查文件是否存在 if not os.path.exists(FLAGS.train_data_path): print(f"❌ 训练文件不存在: {FLAGS.train_data_path}") if not os.path.exists(FLAGS.test_data_path): print(f"❌ 测试文件不存在: {FLAGS.test_data_path}") print(f"⚠️ 优化设置: batch_size={FLAGS.batch_size}, hidden_size={FLAGS.hidden_size}, lr={FLAGS.learning_rate}") session_conf = tf.ConfigProto( allow_soft_placement=True, log_device_placement=False, operation_timeout_in_ms=60000 ) session_conf.gpu_options.allow_growth = True with tf.Session(config=session_conf) as sess: # 加载知识图谱 kg_loader = KnowledgeGraphLoader() kg_loader.load() # 加载数据 print("\n[系统] 加载训练数据...") train_data = read_data_from_csv_file(FLAGS.train_data_path, kg_loader, is_training=True) print("[系统] 加载测试数据...") test_data = read_data_from_csv_file(FLAGS.test_data_path, kg_loader) if not train_data[0] or not test_data[0]: print("❌ 错误: 训练或测试数据为空!") return # 模型配置 class ModelConfig: def __init__(self): self.batch_size = FLAGS.batch_size self.num_skills = kg_loader.static_node_count + 100 # 添加缓冲区 self.num_steps = FLAGS.problem_len self.keep_prob = FLAGS.keep_prob model_config = ModelConfig() print(f"[配置] 技能数量: {model_config.num_skills}") print(f"[配置] 序列长度: {model_config.num_steps}") # 构建模型 print("\n[系统] 构建模型...") with tf.variable_scope("Model"): train_model = StudentModel(is_training=True, config=model_config) tf.get_variable_scope().reuse_variables() test_model = StudentModel(is_training=False, config=model_config) # 优化器和训练操作 global_step = tf.Variable(0, trainable=False) learning_rate = tf.train.exponential_decay( FLAGS.learning_rate, global_step, DECAY_STEPS, DECAY_RATE, staircase=True ) optimizer = tf.train.AdamOptimizer( learning_rate=learning_rate, epsilon=FLAGS.epsilon ) grads_and_vars = optimizer.compute_gradients(train_model.cost) grads, variables = zip(*grads_and_vars) clipped_grads, _ = tf.clip_by_global_norm(grads, FLAGS.max_grad_norm) train_op = optimizer.apply_gradients(zip(clipped_grads, variables), global_step=global_step) # 初始化变量 sess.run(tf.global_variables_initializer()) print(f"[系统] 训练开始 | 批次: {FLAGS.batch_size} | 学习率: {FLAGS.learning_rate}") # 模型保存 checkpoint_dir = "checkpoints_assist2012" os.makedirs(checkpoint_dir, exist_ok=True) saver = tf.train.Saver(max_to_keep=3) best_auc = 0.0 # 训练循环 for epoch in range(FLAGS.epochs): print(f"\n==== Epoch {epoch + 1}/{FLAGS.epochs} ====") current_lr = sess.run(learning_rate) print(f"[学习率] 当前学习率: {current_lr:.7f}") # 训练 train_rmse, train_auc, train_r2, train_loss = run_epoch( sess, train_model, train_data[0], '训练', train_op ) # 评估 if (epoch + 1) % FLAGS.evaluation_interval == 0: test_rmse, test_auc, test_r2, test_loss = run_epoch( sess, test_model, test_data[0], '测试', tf.no_op() ) # 保存最佳模型 if test_auc > best_auc: best_auc = test_auc save_path = saver.save(sess, f"{checkpoint_dir}/best_model.ckpt") print(f"保存最佳模型: {save_path}, AUC={best_auc:.4f}") print("\n训练完成!") if __name__ == "__main__": tf.app.run() 训练代码的测试集的auc 20轮只达到了0.7658;哪里出了问题,如何提高auc
07-02
from utils import generate_report from imblearn.ensemble import EasyEnsembleClassifier eec = EasyEnsembleClassifier(random_state=42) eec.fit(X_train, y_train) y_pred = eec.predict(X_test) plot_distribution(train_data) plot_distribution(test_data) report = generate_report(y_pred, y_test, output=True) accuracy = report['accuracy'] print(accuracy) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\arrays\categorical.py:591, in Categorical.astype(self, dtype, copy) 590 try: --> 591 new_cats = new_cats.astype(dtype=dtype, copy=copy) 592 fill_value = self.categories._na_value ValueError: could not convert string to float: '130A' During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) Cell In[8], line 6 2 from imblearn.ensemble import EasyEnsembleClassifier 5 eec = EasyEnsembleClassifier(random_state=42) ----> 6 eec.fit(X_train, y_train) 8 y_pred = eec.predict(X_test) 10 plot_distribution(train_data) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\base.py:1389, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs) 1382 estimator._validate_params() 1384 with config_context( 1385 skip_parameter_validation=( 1386 prefer_skip_nested_validation or global_skip_validation 1387 ) 1388 ): -> 1389 return fit_method(estimator, *args, **kwargs) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\imblearn\ensemble\_easy_ensemble.py:271, in EasyEnsembleClassifier.fit(self, X, y) 269 self._validate_params() 270 # overwrite the base class method by disallowing `sample_weight` --> 271 return super().fit(X, y) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\utils\validation.py:63, in _deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f(*args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 if extra_args <= 0: ---> 63 return f(*args, **kwargs) 65 # extra_args > 0 66 args_msg = [ 67 "{}={}".format(name, arg) 68 for name, arg in zip(kwonly_args[:extra_args], args[-extra_args:]) 69 ] File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\base.py:1389, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs) 1382 estimator._validate_params() 1384 with config_context( 1385 skip_parameter_validation=( 1386 prefer_skip_nested_validation or global_skip_validation 1387 ) 1388 ): -> 1389 return fit_method(estimator, *args, **kwargs) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\ensemble\_bagging.py:375, in BaseBagging.fit(self, X, y, sample_weight, **fit_params) 372 _raise_for_params(fit_params, self, "fit") 374 # Convert data (X is required to be 2d and indexable) --> 375 X, y = validate_data( 376 self, 377 X, 378 y, 379 accept_sparse=["csr", "csc"], 380 dtype=None, 381 ensure_all_finite=False, 382 multi_output=True, 383 ) 385 if sample_weight is not None: 386 sample_weight = _check_sample_weight(sample_weight, X, dtype=None) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\utils\validation.py:2961, in validate_data(_estimator, X, y, reset, validate_separately, skip_check_array, **check_params) 2959 y = check_array(y, input_name="y", **check_y_params) 2960 else: -> 2961 X, y = check_X_y(X, y, **check_params) 2962 out = X, y 2964 if not no_val_X and check_params.get("ensure_2d", True): File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\utils\validation.py:1370, in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, estimator) 1364 raise ValueError( 1365 f"{estimator_name} requires y to be passed, but the target y is None" 1366 ) 1368 ensure_all_finite = _deprecate_force_all_finite(force_all_finite, ensure_all_finite) -> 1370 X = check_array( 1371 X, 1372 accept_sparse=accept_sparse, 1373 accept_large_sparse=accept_large_sparse, 1374 dtype=dtype, 1375 order=order, 1376 copy=copy, 1377 force_writeable=force_writeable, 1378 ensure_all_finite=ensure_all_finite, 1379 ensure_2d=ensure_2d, 1380 allow_nd=allow_nd, 1381 ensure_min_samples=ensure_min_samples, 1382 ensure_min_features=ensure_min_features, 1383 estimator=estimator, 1384 input_name="X", 1385 ) 1387 y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator) 1389 check_consistent_length(X, y) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\sklearn\utils\validation.py:973, in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_non_negative, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 968 if pandas_requires_conversion: 969 # pandas dataframe requires conversion earlier to handle extension dtypes with 970 # nans 971 # Use the original dtype for conversion if dtype is None 972 new_dtype = dtype_orig if dtype is None else dtype --> 973 array = array.astype(new_dtype) 974 # Since we converted here, we do not need to convert again later 975 dtype = None File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\generic.py:6643, in NDFrame.astype(self, dtype, copy, errors) 6637 results = [ 6638 ser.astype(dtype, copy=copy, errors=errors) for _, ser in self.items() 6639 ] 6641 else: 6642 # else, only a single dtype is given -> 6643 new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors) 6644 res = self._constructor_from_mgr(new_data, axes=new_data.axes) 6645 return res.__finalize__(self, method="astype") File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\internals\managers.py:430, in BaseBlockManager.astype(self, dtype, copy, errors) 427 elif using_copy_on_write(): 428 copy = False --> 430 return self.apply( 431 "astype", 432 dtype=dtype, 433 copy=copy, 434 errors=errors, 435 using_cow=using_copy_on_write(), 436 ) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\internals\managers.py:363, in BaseBlockManager.apply(self, f, align_keys, **kwargs) 361 applied = b.apply(f, **kwargs) 362 else: --> 363 applied = getattr(b, f)(**kwargs) 364 result_blocks = extend_blocks(applied, result_blocks) 366 out = type(self).from_blocks(result_blocks, self.axes) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\internals\blocks.py:758, in Block.astype(self, dtype, copy, errors, using_cow, squeeze) 755 raise ValueError("Can not squeeze with more than one column.") 756 values = values[0, :] # type: ignore[call-overload] --> 758 new_values = astype_array_safe(values, dtype, copy=copy, errors=errors) 760 new_values = maybe_coerce_values(new_values) 762 refs = None File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\dtypes\astype.py:237, in astype_array_safe(values, dtype, copy, errors) 234 dtype = dtype.numpy_dtype 236 try: --> 237 new_values = astype_array(values, dtype, copy=copy) 238 except (ValueError, TypeError): 239 # e.g. _astype_nansafe can fail on object-dtype of strings 240 # trying to convert to float 241 if errors == "ignore": File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\dtypes\astype.py:179, in astype_array(values, dtype, copy) 175 return values 177 if not isinstance(values, np.ndarray): 178 # i.e. ExtensionArray --> 179 values = values.astype(dtype, copy=copy) 181 else: 182 values = _astype_nansafe(values, dtype, copy=copy) File c:\Users\matianht\.conda\envs\nomura\lib\site-packages\pandas\core\arrays\categorical.py:602, in Categorical.astype(self, dtype, copy) 597 except ( 598 TypeError, # downstream error msg for CategoricalIndex is misleading 599 ValueError, 600 ): 601 msg = f"Cannot cast {self.categories.dtype} dtype to {dtype}" --> 602 raise ValueError(msg) 604 result = take_nd( 605 new_cats, ensure_platform_int(self._codes), fill_value=fill_value 606 ) 608 return result ValueError: Cannot cast object dtype to float64 这个代码报错是为什么
07-29
def Data_load_SUMIMO_test_sparse(Config, mean_real, std_real, mean_imag, std_imag): for i, data_path in enumerate(Config.data_path_list): print('加载接收端的频域符号:') relative_path = data_path + '/RxFreqData' # './'表示当前目录,'../'表示上级目录 path_list = sorted(os.listdir(relative_path)) # 返回的是该路径下所有文件和目录组成的列表,sorted方法确保后续path_list列表中元素的顺序保持一致 print(path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]) x1_data = [] for file in path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]: file_path = os.path.join(relative_path, file) feature_data = load(file_path) # 加载mat文件,得到的feature_data为字典类型 x1 = np.asarray(feature_data['group_freqdata'], dtype=np.complex64) # 根据字典中相应的key提取numpy数组,其中'group_freqdata'为变量名字。 x1_data.extend(x1) # x1_data为列表形式 Feature_part1 = np.asarray(x1_data) # 将列表x1_data转换为数组形式, 维度为(TTI=500, S, F, Nr) print('加载接收端的导频估计:') relative_path = data_path + '/LsEstimation' # './'表示当前目录,'../'表示上级目录 path_list = sorted(os.listdir(relative_path)) # 返回的是该路径下所有文件和目录组成的列表,sorted方法确保后续path_list列表中元素的顺序保持一致 print(path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]) x3_data = [] for file in path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]: file_path = os.path.join(relative_path, file) feature_data = load(file_path) # 加载mat文件,得到的feature_data为字典类型 x3 = np.asarray(feature_data['group_lsresult'], dtype=np.complex64) # 根据字典中相应的key提取numpy数组,其中'group_lsresult'为变量名字。 x3_data.extend(x3) # x3_data为列表形式 Feature_part3 = np.asarray(x3_data) # 将列表x3_data转换为数组形式 print('---进行插值----') # 最近邻插值 start_time = time.perf_counter() # Reshape LS result to extract pilot tones only: assume we have P = 11 pilots pilot_mask = [f for f in range(120) if f % 6 == 0] # [0, 6, 12, 18, ..., 114] print("Feature_part3.shape =", Feature_part3.shape) # 输出类似:(1000, 14, 120, 4, 2) → 5 维!不能 unpack 成 B,S,F,C if Feature_part3.ndim == 5: B, S, F, Nr, Nt = Feature_part3.shape elif Feature_part3.ndim == 4: B, S, F, C = Feature_part3.shape else: raise ValueError(f"Unexpected shape: {Feature_part3.shape}") pilot_data_train = Feature_part3[:, :, pilot_mask, :, :] # 插值回完整频带 Feature_part3 = fast_batch_interpolation(pilot_data_train, pilot_indices=pilot_mask, F=120) # rows, _, _, _, layer_num = Feature_part3.shape # for m in range(rows): # for j in range(layer_num): # array = Feature_part3[m, :, :, :, j] # (TTI, S, F, Nr, Nt) # Feature_part3[m, :, :, :, j] = nearest_neighbor_interpolation_single_pilot_01_sparse(array) end_time = time.perf_counter() print('插值所用时间为:{}min'.format((end_time - start_time) / 60)) print('---插值完成---') print('加载标签:') relative_path = data_path + '/Label' # './'表示当前目录,'../'表示上级目录 path_list = sorted(os.listdir(relative_path)) # 返回的是该路径下所有文件和目录组成的列表,sorted方法确保后续path_list列表中元素的顺序保持一致 print(path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]) y_data = [] for file in path_list[Config.segment_num[i][0]:Config.segment_num[i][1]]: file_path = os.path.join(relative_path, file) feature_data = load(file_path) # 加载mat文件,得到的feature_data为字典类型 y = feature_data['group_txcwbits'] # 根据字典中相应的key提取numpy数组,其中'group_txcwbits'为变量名字。 y_data.extend(y) # y_data为列表形式 y_test = np.asarray(y_data, dtype=np.float32) # 将列表y_data转换为数组形式,dtype为'float32' # -------------------------------------合并输入特征------------------------------------------- # 调整Feature_part3的维度,(TTI, S, F, 4, 2) --->(TTI, S, F, 8) Feature_part3 = Feature_part3.reshape(Feature_part3.shape[0], Feature_part3.shape[1], Feature_part3.shape[2], Feature_part3.shape[3] * Feature_part3.shape[4]) # 将Feature_part1和Feature_part3按最后一维拼起来 x_test = np.concatenate((Feature_part1, Feature_part3), axis=3) # (TTI, S, F, 12) x_test_input = np.concatenate([x_test.real, x_test.imag], axis=-1) # (B, S, F, 24) # -----------------对测试数据进行标准化预处理--------------------- eps = 1e-8 x_test_norm = (x_test_input.real - mean_real) / (std_real + eps) + 1j * (x_test_input.imag - mean_imag) / (std_imag+eps) # 打印数据集大小信息 print('-' * 100) print('加载测试集为:{}'.format(data_path)) print('测试集大小为:{}个TTI'.format(len(y_test))) # 模型预测,输入数据(不需要标签),输出预测结果 y_pred = Config.load_model.predict(x_test_norm, batch_size=1, verbose=2) # (TTI, S, F, Nt, B) # 取相应QAM对应的软比特预测结果 if Config.Modulation == '64QAM': y_pred_1 = y_pred[..., :6] elif Config.Modulation == '16QAM': y_pred_1 = y_pred[..., :4] else: y_pred_1 = y_pred[..., :2] # 利用网络的预测结果进行硬判决,大于0判为1,小于0判为0 array = np.where(y_pred_1 > 0, 1, 0) same_element = np.sum(array == y_test) total_element = array.size ratio = same_element / total_element print('AI预测后的Raw BER为:{}'.format(1 - ratio)) print('-' * 100) 代码报错: Traceback (most recent call last): File "3-train_simulation_64QAM_MCS28_LN_GN_group2_sparse_SNR.py", line 295, in <module> Data_load_SUMIMO_test_sparse(TestConfig, mean_real, std_real, mean_imag, std_imag) File "/home/ai/YXJ/3-SUMIMO_train/SUMIMO_Tools.py", line 2133, in Data_load_SUMIMO_test_sparse y_pred = Config.load_model.predict(x_test_norm, batch_size=1, verbose=2) # (TTI, S, F, Nt, B) File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/tmp/__autograph_generated_filerez7l2d0.py", line 15, in tf__predict_function retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope) ValueError: in user code: File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1845, in predict_function * return step_function(self, iterator) File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1834, in step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1823, in run_step ** outputs = model.predict_step(data) File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1791, in predict_step return self(x, training=False) File "/home/ai/miniconda3/envs/venv/lib/python3.7/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None ValueError: Exception encountered when calling layer "mimo_deep_rx" (type MIMODeepRx). Could not find matching concrete function to call loaded from the SavedModel. Got: Positional arguments (2 total): * <tf.Tensor 'inputs:0' shape=(1, 14, 120, 24) dtype=complex64> * False Keyword arguments: {} Expected these arguments to match one of the following 4 option(s): Option 1: Positional arguments (2 total): * TensorSpec(shape=(None, 14, 120, 12), dtype=tf.complex64, name='inputs') * False Keyword arguments: {} Option 2: Positional arguments (2 total): * TensorSpec(shape=(None, 14, 120, 12), dtype=tf.complex64, name='inputs') * True Keyword arguments: {} Option 3: Positional arguments (2 total): * TensorSpec(shape=(None, 14, 120, 12), dtype=tf.complex64, name='input_1') * False Keyword arguments: {} Option 4: Positional arguments (2 total): * TensorSpec(shape=(None, 14, 120, 12), dtype=tf.complex64, name='input_1') * True Keyword arguments: {} Call arguments received by layer "mimo_deep_rx" (type MIMODeepRx): • args=('tf.Tensor(shape=(1, 14, 120, 24), dtype=complex64)',) • kwargs={'training': 'False'}
10-29
PS D:\桌面\预测模型> & C:/Python313/python.exe d:/桌面/预测模型/lstm_sticker.py 2025-11-03 15:58:02.819705: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-11-03 15:58:04.320468: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. d:\桌面\预测模型\lstm_sticker.py:11: FutureWarning: YF.download() has changed argument auto_adjust default to True data = yf.download(ticker, start='2017-01-01', end='2025-07-11') Failed to get ticker 'NVDA' reason: Failed to perform, curl: (77) error setting certificate verify locations: CAfile: C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\certifi\cacert.pem CApath: none. See https://curl.se/libcurl/c/libcurl-errors.html first for more details. [*********************100%***********************] 1 of 1 completed 1 Failed download: ['NVDA']: SSLError('Failed to perform, curl: (77) error setting certificate verify locations: CAfile: C:\\Users\\立立\\AppData\\Roaming\\Python\\Python313\\site-packages\\certifi\\cacert.pem CApath: none. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.') Empty DataFrame Columns: [(Adj Close, NVDA), (Close, NVDA), (High, NVDA), (Low, NVDA), (Open, NVDA), (Volume, NVDA)] Index: [] Traceback (most recent call last): File "d:\桌面\预测模型\lstm_sticker.py", line 19, in <module> scaled_data = scaler.fit_transform(close_prices) File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\utils\_set_output.py", line 316, in wrapped data_to_wrap = f(self, X, *args, **kwargs) File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\base.py", line 894, in fit_transform return self.fit(X, **fit_params).transform(X) ~~~~~~~~^^^^^^^^^^^^^^^^^ File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\preprocessing\_data.py", line 454, in fit return self.partial_fit(X, y) ~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\base.py", line 1365, in wrapper return fit_method(estimator, *args, **kwargs) File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\preprocessing\_data.py", line 494, in partial_fit X = validate_data( self, ...<3 lines>... ensure_all_finite="allow-nan", ) File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\utils\validation.py", line 2954, in validate_data out = check_array(X, input_name="X", **check_params) File "C:\Users\立立\AppData\Roaming\Python\Python313\site-packages\sklearn\utils\validation.py", line 1128, in check_array raise ValueError( ...<3 lines>... ) ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required by MinMaxScaler. PS D:\桌面\预测模型> ^C
最新发布
11-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值