<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python on The Personal Website of Myosotics</title>
    <link>/tags/python/</link>
    <description>Recent content in Python on The Personal Website of Myosotics</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-US</language>
    <lastBuildDate>Fri, 10 Nov 2023 00:00:00 +0000</lastBuildDate><atom:link href="/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Portfolio Selection with Feature Screening</title>
      <link>/blog/2023-11-10-portfolio-selection-with-feature-screening/</link>
      <pubDate>Fri, 10 Nov 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-11-10-portfolio-selection-with-feature-screening/</guid>
      <description>算法和代码均来自文章：Jin-Hong Du, Yifeng Guo &amp;amp; Xueqin Wang (2023) High-Dimensional Portfolio Selection with Cardinality Constraints, Journal of the American Statistical Association, 118:542, 779-791, DOI: 10.1080/01621459.2022.2133718.
首先加載reticulate包，方便在Rmarkdown中使用Python。
library(reticulate) ## Warning: 程辑包&#39;reticulate&#39;是用R版本4.1.3 来建造的 use_python(&#39;E:/software/Program Files/python3.11.0&#39;) 一个小测试 构建一个数据集用来测试
import numpy as np n = 20 d = 100 np.random.seed(0) X = np.random.rand(n,d) + 0.5 X.shape ## (20, 100) from spo import spo_l1_path ws, lambdas, gaps, n_iters, n_active_features = spo_l1_path(X, func=0, n_lambdas=50, screen=True, max_iter=int(1e4), f=200, tol=1e-3) ## 0%| | 0/50 [00:00&amp;lt;?</description>
    </item>
    
    <item>
      <title>Python基础——版本查看及第三方库操作</title>
      <link>/blog/2023-10-19-python/</link>
      <pubDate>Thu, 19 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-19-python/</guid>
      <description>版本查看 查看python版本 使用cmd命令查看(只能查看默认环境变量的python)。
输入win + r进入命令窗口。输入python即可查看默认的 python 版本。 或者输入python --version命令进行查看 查看python的路径 在命令窗口中输入where python，它会显示python对应的路径，多个版本会显示多个路径 默认的python版本就是cmd进入的python 首先查看高级系统设置并进入环境变量页面 查看环境变量的python。一般查看PATH变量。 第三方库操作 查看第三方库 使用cmd命令查看(只能查看默认环境变量的python) 输入win + r进入命令窗口。输入pip list即可查看安装的第三方库。 通过安装的路径来看python的包 在命令窗口中输入where python，它会显示python对应的路径，多个版本会显示多个路径。 复制进入对应python.exe的的上一级文件，此处我进入的是：E:\software\Program Files\Python 之后一般第三方库的路径实在.\Lib\site-packages中。 手动配置pip镜像源 手动配置，windows下，直接在user目录中创建一个pip目录，再新建文件pip.ini。 接着打开pip.ini文件，复制粘贴以下内容并保存。
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple 注意此处是设置了清华源为例，国内镜像源有如下
清华 https://pypi.tuna.tsinghua.edu.cn/simple 豆瓣 http://pypi.douban.com/simple/ 阿里 http://mirrors.aliyun.com/pypi/simple/ 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ 第三方库安装 pip安装大法 在命令行窗口使用pip install packages即可，例如，以安装numba库为例。 </description>
    </item>
    
    <item>
      <title>在Rmarkdown中调用Python代码</title>
      <link>/blog/2023-10-19-rmarkdown-python/</link>
      <pubDate>Thu, 19 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-19-rmarkdown-python/</guid>
      <description>在Rmarkdown中调用Python代码块需要用到reticulate包
install.packages(&amp;quot;reticulate&amp;quot;) 在我们运行python代码块之前首先需要设置好Python环境。下面我们需要指定Python路径， 在命令窗口输入where python看python的路径 接下来在R中指定Pyrhon路径
library(reticulate) use_python(&#39;E:/software/Program Files/python3.11.0&#39;) 最后即可在Rmarkdown中运行python代码块了
import numpy as np import matplotlib.pyplot as plt # 计算正弦曲线上的 x 和 y 坐标 x = np.arange(0, 3*np.pi, 0.1) y = np.sin(x) plt.title(&#39;sine wave form&#39;) # 使用 matplotlib 来绘制点 plt.plot(x, y) plt.show() </description>
    </item>
    
  </channel>
</rss>
