def metricas_ponderadas_segun_concordancia(verdaderos_negativos, falsos_positivos, falsos_negativos, verdaderos_positivos): tn = sum(1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in verdaderos_negativos) fp = sum(1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in falsos_positivos) fn = sum(1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in falsos_negativos) tp = sum(1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in verdaderos_positivos) return tn, fp, fn, tp
def metricas_ponderadas_segun_concordancia(verdaderos_negativos, falsos_positivos, falsos_negativos, verdaderos_positivos): tn = sum( 1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in verdaderos_negativos) fp = sum( 1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in falsos_positivos) fn = sum( 1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in falsos_negativos) tp = sum( 1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in verdaderos_positivos) return tn, fp, fn, tp
print('') if args.parametros_clasificador: print('') print("Parametros del clasificador:") for nombre_parametro, valor_parametro in clasificador_usado.get_params().items(): print("\t{clave}: {valor}".format(clave=nombre_parametro, valor=valor_parametro)) print('') if args.cross_validation and not args.evaluar: cross_validation_y_reportar(clasificador_usado, features, clases, 5) print("Entrenando clasificador...") if args.ponderar_segun_votos: if args.clasificador == "SVM": sample_weights = [1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in entrenamiento] clasificador_usado.fit(features_entrenamiento, clases_entrenamiento, sample_weight=sample_weights) elif args.clasificador == "DT": sample_weights = [1 - 2 * entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in entrenamiento] clasificador_usado.fit(features_entrenamiento, clases_entrenamiento, sample_weight=sample_weights) else: clasificador_usado.fit(features_entrenamiento, clases_entrenamiento) else: clasificador_usado.fit(features_entrenamiento, clases_entrenamiento) if args.ponderar_segun_votos: medidas_ponderadas = "concordancia" else: medidas_ponderadas = ""
print("Parametros del clasificador:") for nombre_parametro, valor_parametro in clasificador_usado.get_params( ).items(): print("\t{clave}: {valor}".format(clave=nombre_parametro, valor=valor_parametro)) print('') if args.cross_validation and not args.evaluar: cross_validation_y_reportar(clasificador_usado, features, clases, 5) print("Entrenando clasificador...") if args.ponderar_segun_votos: if args.clasificador == "SVM": sample_weights = [ 1 - entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in entrenamiento ] clasificador_usado.fit(features_entrenamiento, clases_entrenamiento, sample_weight=sample_weights) elif args.clasificador == "DT": sample_weights = [ 1 - 2 * entropia(tweet.votos_humor / tweet.votos) if tweet.votos > 0 else 1 for tweet in entrenamiento ] clasificador_usado.fit(features_entrenamiento, clases_entrenamiento, sample_weight=sample_weights) else: clasificador_usado.fit(features_entrenamiento,