- 博客(73)
- 收藏
- 关注
原创 tensorflow 实现CNN
# -*- coding: utf-8 -*-"""Created on Wed Dec 2 19:02:44 2020@author: mxc"""import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamnist=input_data.read_data_sets('MNIST_data',one_hot=True)learning_rate=1e-4keep_prob_rate
2022-03-16 18:42:32
1247
1
原创 Keras实现SEnet实验
import numpy as npimport pandas as pdfrom sklearn.model_selection import train_test_split, KFoldfrom sklearn.utils import shufflefrom tensorflow.keras.layers import Dense, Conv2D, BatchNormalization, Activation, add, multiplyfrom tensorflow.keras.laye
2022-03-16 18:41:08
2660
原创 tensorflow 实现 RNN 实验
import numpy as npimport tensorflow as tfimport osimport jsonstart_token = 'B'end_token = 'E'model_dir = './model' def process_poems(): poems_vector = np.load('poems_index.npy', allow_pickle=True) with open('word2int.json','r') as f:
2022-03-16 18:39:45
1453
原创 C++ vector与set转换
int removeDuplicates(vector<int>& nums) { set<int> st(nums.begin(), nums.end()); nums.assign(st.begin(), st.end()); return st.size(); }
2022-03-07 16:37:47
2681
原创 python连接mysql数据库并导入csv文件
import csvL = csv.reader(open('small_user.csv'))import pymysqldb = pymysql.connect(host='127.0.0.1', user='root', passwd='', db='taobao', charset='utf8')# 远程访问指定IP上的数据库cursor = db.cursor()#user_id,item_id,behavior_type,user_geohash,
2021-06-27 16:02:01
1312
原创 Python3:Python+spark编程实战
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2021/5/13 15:24# @Author : Pyuser# @Site : # @File : 尝试.py# @Software: PyCharm#studentExample 例子 练习def map_func(x): s = x.split() return (s[0], [int(s[1]),int(s[2]),int(s[3])]
2021-05-14 08:21:58
298
原创 Python封装类序列化反序列化
import pickleclass Person(): def __init__(self,bank,telephone,month,money): self.bank = bank self.telephone = telephone self.month=month self.money=moneytotal=[]with open("MR数据的统计.txt")as f: file=f.read().splitlines().
2021-05-12 15:55:00
151
原创 python回归分析lasso,ridge,SVM,rf,kfold,pcc
from sklearn.linear_model import Ridge, Lasso, ElasticNetCVfrom sklearn.model_selection import GridSearchCV, KFoldfrom sklearn.svm import SVRfrom sklearn.ensemble import AdaBoostRegressor, RandomForestRegressorfrom sklearn.neighbors import KNeighborsRe
2021-04-08 13:29:06
811
原创 依存树
import spacyimport networkx as nximport reimport nltkimport nltk.data#情感分析from textblob import TextBlobfrom nltk.corpus import sentiwordnetfrom collections import defaultdictnlp=spacy.load('en_core_web_sm')alltext=[]sentext=[]juzi=''file = o
2020-12-03 19:41:35
506
原创 python五子棋
"""五子棋之人机对战"""import sysimport randomimport pygamefrom pygame.locals import *import pygame.gfxdrawfrom collections import namedtupleChessman = namedtuple('Chessman', 'Name Value Color')Point = namedtuple('Point', 'X Y')BLACK_CHESSMAN = Chessman
2020-12-01 20:11:17
471
原创 神经网络task1
import osimport numpy as npimport tensorflow as tf from tensorflow import kerasfrom tensorflow.keras import layers, datasets, optimizersos.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"def mnist_dataset(): (x, y), (x_test, y_test) = datasets.mnist.load_d
2020-11-26 10:49:24
255
原创 Python 刷题
class Solution: def longestZigZag(self, root: TreeNode) -> int: if root == None: return 0 self.max_ = 0 self.dfs(root, 0, 0) return self.max_ def dfs(self, root, prev, depth): self.max_ =
2020-11-15 20:53:57
152
原创 BosonNLP情感词典 评论情感分析
from snownlp import SnowNLPimport pandas as pdfrom collections import defaultdictimport osimport reimport jiebaimport codecs'''#读取评论内容的.txt文件txt = open('C:/Users/24224/Desktop/1.txt',encoding='utf-8')text = txt.readlines()print(text)#确认读取文件成功,
2020-11-10 20:16:36
7421
5
原创 TFIDF词频-逆向文件频率算法Python
# -*- coding: utf-8 -*-import mathimport reimport codecsfrom operator import itemgetterimport jiebaimport jieba.posseg as psegimport osimport sysfrom sklearn.feature_extraction.text import CountVectorizerfrom sklearn.feature_extraction.text impor
2020-10-17 18:29:02
553
原创 Python爬虫广度优先代码实现
# encoding=utf-8from bs4 import BeautifulSoupimport socketimport urllib.request as requestimport reclass linkQuence: def __init__(self): # 已访问的url集合 self.visted = [] # 待访问的url集合 self.unVisited = [] # 获取访问过的u
2020-06-07 23:43:20
545
原创 M-H Python实现
import randomfrom scipy.stats import gamma,rayleighimport matplotlib.pyplot as pltdef rayleigh_dist_prob(x,a): #提议分布 y = rayleigh.pdf(x,a) return ydef gamma_dist_prob(x): #提议分布 y = gamma.pdf(x,1,scale=1) return ya=1.9sigmaf=4T = 1000
2020-05-30 10:53:26
504
原创 Openmp 矩阵乘法和奇偶排序
这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入欢迎使用Markdown编辑器你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar
2020-05-27 09:36:37
1187
原创 Python 层次聚类+K-means算法+可视化 数据挖掘
层次聚类:import pandas as pdimport scipy.cluster.hierarchy as schfrom sklearn.cluster import AgglomerativeClusteringfrom sklearn.preprocessing import MinMaxScalerfrom matplotlib import pyplot as plt# 读取数据data = pd.read_csv(r'C:/Users/24224/Desktop/count
2020-05-25 09:39:44
3037
1
原创 没阅读完的Python代码(2)
import numpy as npimport matplotlibimport matplotlib.pyplot as pltfrom distutils.version import LooseVersionfrom scipy.stats import normfrom sklearn.neighbors import KernelDensity# `normed` is being deprecated in favor of `density` in histogramsif L
2020-05-24 10:01:28
179
原创 没阅读完的Python代码
import tushare as tsimport pandas as pdimport matplotlib.pyplot as pltimport numpy as npimport seaborn as snstoken = '4b4d823d700aff8ebece51d15ad76ccb3f6f795fa858da4030d1c295'ts.set_token(token)pro = ts.pro_api()df = pro.index_daily(ts_code='399300
2020-05-24 09:59:33
131
原创 SVM 大篷车:家庭移动政策预测
数据集用来训练和检验预测模型,建立了5822个客户的记录。每个记录由86个属性组成,包含社会人口数据和产品的所有关系。社会人口数据是有派生邮政编码派生而来,生活在相同邮政编码地区的客户具有相同的社会人口属性。第86个属性:“大篷车:家庭移动政策”,为目标变量。预测的数据集为预测最后一个属性值。预测数据共有4003条。预测数据为85个属性。实验就是对后一个属性进行预测为二分类问题。即对第86个属性进行预测。可以在分类前对数据进行清洗。具体内容可以见网站:http://liacs.leidenuniv.nl/~
2020-05-16 23:43:56
342
原创 Pthread多线程求矩阵乘法并计算运行时间
其中 m ,n, 线程数 从. txt文件中读取,以空格或回车为分隔符#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <time.h>#include <sys/time.h>#define MAX 10000int thread_count; // number of threadsint m; // rowint n; // column
2020-05-13 15:05:11
1515
原创 Pthread多线程求π值(忙等待,互斥量,信号量,条件变量)并计算运行时间
忙等待#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include <time.h>#include <sys/time.h>int thread_count; //thread's numint n = 1000000; //10^6double sum = 0.0;int flag = 0;
2020-05-13 14:57:44
2437
原创 鸢尾花 决策树 计算信息增益 信息增益率 基尼指数 混淆矩阵 召回率 精确率
import numpy as npfrom sklearn.datasets import load_irisfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_score, confusion_matrix, recall_score # 混淆矩阵import...
2020-05-04 09:58:00
1107
原创 决策树 鸢尾花分类 数据挖掘Python
from sklearn.tree import DecisionTreeClassifierfrom sklearn import datasetsfrom sklearn.metrics import accuracy_scorefrom sklearn.model_selection import train_test_splitiris = datasets.load_iris(...
2020-05-01 10:30:25
717
原创 Python 生成和为1随机数
import numpy as np, numpy.randoma=np.random.dirichlet(np.ones(2),size=1)print(a)狄利克雷分布,如果生成20个和为1 随机数可以改成 np.ones(20)
2020-05-01 09:06:30
8354
原创 MPI随机生成矩阵 矩阵乘法 并计时
#include <stdio.h>#include "mpi.h"#include <string.h>#include <stdlib.h>#include <math.h>#include <time.h>//生成随机矩阵int **generate_matrix(int guimo){ int num = ...
2020-04-22 09:38:02
905
1
原创 python绘制小猪佩奇
from turtle import *def nose(x, y): # 鼻子 penup() # 提起笔 goto(x, y) # 定位 pendown() # 落笔,开始画 setheading(-30) # 将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南) begin_fill() # 准备开始填充...
2020-04-20 19:02:26
211
原创 Python 实现百度翻译
from urllib import request,parseimport jsondef fanyi(keyword): base_url = 'https://fanyi.baidu.com/sug' # 构建请求对象 data = { 'kw': keyword } data = parse.urlencode(data) ...
2020-04-20 18:54:45
3919
原创 Python 线性回归处理糖尿病数据 计算MSE等
实验内容:糖尿病数据预测根据美国疾病控制预防中心的数据,现在美国1/7的成年人患有糖尿病。但是到2050年,这个比例将会快速增长至高达1/3。在UCL机器学习数据库里一个糖尿病数据集,通过这一数据集,学习如何利用线性回归分析来预测糖尿病:数据地址:https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/di...
2020-04-20 18:18:50
2364
原创 MPI 奇偶排序
编译:mpicc -o 目标文件 源文件.cpp运行:mpirun -n 进程数 -machinefile ./machinefile ./目标文件带注释版(但是有点小的语法错误)#include "mpi.h"#include <stdio.h>#include <stdlib.h>//exit #include <malloc.h>#incl...
2020-04-09 00:34:58
1201
原创 c语言 矩阵乘法
#include<stdio.h>#include<iostream>using namespace std;int main(){ int A[100][100],B[100][100],A_n,A_m,B_n,B_m,i,j,k,sum; while(scanf("%d%d",&A_n,&A_m) && ( A_n ...
2020-03-23 14:45:08
266
原创 c语言实现奇偶排序
#include<stdio.h>#include<stdlib.h>#include<stdbool.h>#includeusing namespace std;void swap(int *a, int *b){ int t; t = *a; *a = *b; *b = t;}void ...
2020-03-23 12:04:30
2069
原创 C语言 梯形积分法
#include<iostream>#include<math.h>using namespace std;int main(){ float fun(float x); float a,b; cout<<"请输入函数X^2的定积分的下限a和上限b:"; cin>>a>>b; int n=50;//将区间划分成50份 ...
2020-03-17 21:20:33
1488
原创 Python 字母计数
输入字符串输出出现次数最多的字母及其出现次数样例:输入:abcccd输出: c 3import operatora=input()b=int(len(a))c=[]i=0while i <b: c.append(a[i:i+1]) i+=1a_dict={}for b in c: if b in a_dict: a_dict...
2020-03-14 17:26:47
3425
2
原创 Python 去除列表中重复数字,统计共有多少不同数字
a=list(map(int, input().strip().split()))b=list(set(a))print(int(len(b)))
2020-03-10 09:59:39
1448
原创 C++实现数据结构之遍历树
题目要求:给出二叉树后序遍历和中序遍历,请给出层序遍历补充知识(头文件的):(1) 队列:https://blog.youkuaiyun.com/u010112268/article/details/81162097(2)algorithm :https://blog.youkuaiyun.com/hy971216/article/details/80056933容器排序,在STL标砖容器中,只有vector/...
2020-03-02 16:41:25
284
原创 python出现 ValueError: could not convert string to float: '75,871.62' 字符中间带逗号如何转换为浮点型
如何去掉数字字符串里面的逗号float转化str时str不能为空,不能带有’\n’否则就会报错ValueError: could not convert string to float:f = open("C:/Users/24224/Documents/Tencent Files/2422443606/FileRecv/fp.txt")s = f.read()a = list(s.sp...
2020-02-22 17:11:33
934
原创 有用的代码片段集合(1)
import reclass WordDictionary: def __init__(self): self.words = '#' def addWord(self, word): self.words += word + '#' def search(self, word): return bool(re.search...
2020-02-10 18:07:07
162
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人